java.lang.Object
org.apache.johnzon.core.Snippet
Constructs 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 ClassesModifier and TypeClassDescriptionprivate classThere are several buffers involved in the creation of a json string.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final jakarta.json.stream.JsonGeneratorFactoryprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionSnippet(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
Modifier and TypeMethodDescriptionstatic 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 Stringof(int max, jakarta.json.JsonValue value) Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length.of(jakarta.json.JsonValue value) Create a serialized json representation of the supplied JsonValue, truncating the value to the specified max length.
-
Field Details
-
max
private final int max -
generatorFactory
private final jakarta.json.stream.JsonGeneratorFactory generatorFactory
-
-
Constructor Details
-
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 Details
-
of
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
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
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
-