- java.lang.Object
-
- org.apache.johnzon.core.Snippet
-
public class Snippet extends java.lang.ObjectConstructs short snippets of serialized JSON text representations of JsonValue instances in a way that is ideal for error messages. Instances of Snippet are thread-safe, reusable and memory-safe. Snippet serializes only enough of the json to fill the desired snippet size and is therefore safe to use regardless of the size of the JsonValue.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSnippet.BufferThere are several buffers involved in the creation of a json string.private static classSnippet.PassthroughWriter
-
Field Summary
Fields Modifier and Type Field Description private jakarta.json.stream.JsonGeneratorFactorygeneratorFactoryprivate intmax
-
Constructor Summary
Constructors Constructor Description Snippet(int max, jakarta.json.stream.JsonGeneratorFactory generatorFactory)This is the preferred approach to using Snippet in any context where there is an existing JsonGeneratorFactory in scope.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Snippetof(int max)This factory should be used only in static or other scenarios were there is no JsonGeneratorFactory instance in scope - ie external code.static java.lang.Stringof(int max, jakarta.json.JsonValue value)Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length.java.lang.Stringof(jakarta.json.JsonValue value)Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length.
-
-
-
Constructor Detail
-
Snippet
public Snippet(int max, jakarta.json.stream.JsonGeneratorFactory generatorFactory)This is the preferred approach to using Snippet in any context where there is an existing JsonGeneratorFactory in scope.- Parameters:
max- the maximum length of the serialized json produced via of()generatorFactory- the JsonGeneratorFactory created by the user
-
-
Method Detail
-
of
public java.lang.String of(jakarta.json.JsonValue value)
Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length. Truncated text appears with a suffix of "..." This method is thread safe.- Parameters:
value- the JsonValue to be serialized as json text- Returns:
- a potentially truncated json text
-
of
public static Snippet of(int max)
This factory should be used only in static or other scenarios were there is no JsonGeneratorFactory instance in scope - ie external code.- Parameters:
max- the maximum length of the serialized json produced via of()
-
of
public static java.lang.String of(int max, jakarta.json.JsonValue value)Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length. Truncated text appears with a suffix of "..." This method is thread safe. Avoid using this method in any context where there already is a JsonGeneratorFactory instance in scope. For those scenarios use the constructor that accepts a JsonGeneratorFactory instead.- Parameters:
max- the maximum length of the serialized json textvalue- the JsonValue to be serialized as json text- Returns:
- a potentially truncated json text
-
-