Jackson Glossary: SerializedString
Package: org.codehaus.jackson.io
Jar: jackson-core
Role
This value class (introduced in Jackson 1.6; improved slightly in 1.7, with introduction of SerializableString interface) was added to allow for optimized handling of Strings; mostly that for property names, but also possibly for JSON String values. Idea is that value class contains not only String value itself, but also optional JSON-quoted and UTF-8 encoded forms of the String. These additional forms are lazily constructed, but once constructed can be reused multiple times. This can significantly improve serialization speed in cases where same names are used multiple times; this is the case, for example, with Bean serializers that are cached and reused.
Usage
1 // instances are usually created as static singletons, but:
2 final static SerializedString PROPERTY_NAME_VALUE = new SerializedString("value");
3
4 ...
5
6 // sample method that adds a property in JSON Object being output:
7 public void writeValueProperty(JsonGenerator jgen, int value) throws IOException
8 {
9 jgen.writeFieldName(str);
10 jgen.writeNumber(value);
11 }
Related classes
This class implements SerializableString
Back to Jackson Term Glossary
