com.fasterxml.jackson.core.SerializableString Java Examples
The following examples show how to use
com.fasterxml.jackson.core.SerializableString.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonEncoder.java From metafacture-core with Apache License 2.0 | 6 votes |
/** * By default JSON output does only have escaping where it is strictly * necessary. This is recommended in the most cases. Nevertheless it can * be sometimes useful to have some more escaping. * * @param escapeCharacters an array which defines which characters should be * escaped and how it will be done. See * {@link CharacterEscapes}. In most cases this should * be null. Use like this: * <pre>{@code int[] esc = CharacterEscapes.standardAsciiEscapesForJSON(); * // and force escaping of a few others: * esc['\''] = CharacterEscapes.ESCAPE_STANDARD; * JsonEncoder.useEscapeJavaScript(esc); * }</pre> */ public void setJavaScriptEscapeChars(final int[] escapeCharacters) { final CharacterEscapes ce = new CharacterEscapes() { private static final long serialVersionUID = 1L; @Override public int[] getEscapeCodesForAscii() { if (escapeCharacters == null) { return CharacterEscapes.standardAsciiEscapesForJSON(); } return escapeCharacters; } @Override public SerializableString getEscapeSequence(final int ch) { final String jsEscaped = escapeChar((char) ch); return new SerializedString(jsEscaped); } }; jsonGenerator.setCharacterEscapes(ce); }
Example #2
Source File: PropertyFilteringJsonGenerator.java From jackson-jaxrs-propertyfiltering with Apache License 2.0 | 6 votes |
@Override public void writeFieldName(SerializableString name) throws IOException { TokenFilter state = filterContext.setFieldName(name.getValue()); if (state == null) { itemFilter = null; } else if (state == TokenFilter.INCLUDE_ALL) { itemFilter = state; delegate.writeFieldName(name); } else { state = state.includeProperty(name.getValue()); itemFilter = state; if (state != null) { delegate.writeFieldName(name); } } }
Example #3
Source File: WritableObjectId.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Method called to output Object Id as specified. */ public void writeAsField(JsonGenerator gen, SerializerProvider provider, ObjectIdWriter w) throws IOException { idWritten = true; // 03-Aug-2013, tatu: Prefer Native Object Ids if available if (gen.canWriteObjectId()) { // Need to assume String(ified) ids, for now... could add 'long' variant? gen.writeObjectId(String.valueOf(id)); return; } SerializableString name = w.propertyName; if (name != null) { gen.writeFieldName(name); w.serializer.serialize(id, gen, provider); } }
Example #4
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 6 votes |
public static EnumValues constructFromName(MapperConfig<?> config, Class<Enum<?>> enumClass) { // Enum types with per-instance sub-classes need special handling Class<? extends Enum<?>> enumCls = ClassUtil.findEnumType(enumClass); Enum<?>[] enumValues = enumCls.getEnumConstants(); if (enumValues == null) { throw new IllegalArgumentException("Cannot determine enum constants for Class "+enumClass.getName()); } String[] names = config.getAnnotationIntrospector().findEnumValues(enumCls, enumValues, new String[enumValues.length]); SerializableString[] textual = new SerializableString[enumValues.length]; for (int i = 0, len = enumValues.length; i < len; ++i) { Enum<?> en = enumValues[i]; String name = names[i]; if (name == null) { name = en.name(); } textual[en.ordinal()] = config.compileString(name); } return new EnumValues(enumClass, textual); }
Example #5
Source File: JSONUtil.java From webanno with Apache License 2.0 | 5 votes |
@Override public SerializableString getEscapeSequence(int aCh) { switch (aCh) { case '\u2028': return new SerializedString("\\u2028"); case '\u2029': return new SerializedString("\\u2029"); default: return null; } }
Example #6
Source File: SensitiveJsonGenerator.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public void writeString(final SerializableString text) throws IOException { if (text != null && isSensitiveAttribute()) { super.writeString(passwordHelper.encrypt(text.getValue())); } else { super.writeString(text); } }
Example #7
Source File: MessageMarshaller.java From curiostack with MIT License | 5 votes |
@Override @Nullable public SerializableString getEscapeSequence(int ch) { switch (ch) { case '<': return HTML_ESCAPED_LESS_THAN; case '>': return HTML_ESCAPED_GREATER_THAN; default: return null; } }
Example #8
Source File: RawValue.java From lams with GNU General Public License v2.0 | 5 votes |
protected void _serialize(JsonGenerator gen) throws IOException { if (_value instanceof SerializableString) { gen.writeRawValue((SerializableString) _value); } else { gen.writeRawValue(String.valueOf(_value)); } }
Example #9
Source File: RawValue.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { if (_value instanceof JsonSerializable) { ((JsonSerializable) _value).serializeWithType(gen, serializers, typeSer); } else if (_value instanceof SerializableString) { /* Since these are not really to be deserialized (with or without type info), * just re-route as regular write, which will create one... hopefully it works */ serialize(gen, serializers); } }
Example #10
Source File: ObjectComposer.java From jackson-jr with Apache License 2.0 | 5 votes |
public ArrayComposer<ObjectComposer<PARENT>> startArrayField(SerializableString fieldName) throws IOException, JsonProcessingException { _closeChild(); _generator.writeFieldName(fieldName); return _startArray(this, _generator); }
Example #11
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Method used for serialization and introspection by core Jackson code. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public EnumMap<?,SerializableString> internalMap() { EnumMap<?,SerializableString> result = _asMap; if (result == null) { // Alas, need to create it in a round-about way, due to typing constraints... Map<Enum<?>,SerializableString> map = new LinkedHashMap<Enum<?>,SerializableString>(); for (Enum<?> en : _values) { map.put(en, _textual[en.ordinal()]); } result = new EnumMap(map); } return result; }
Example #12
Source File: ObjectComposer.java From jackson-jr with Apache License 2.0 | 5 votes |
public ObjectComposer<ObjectComposer<PARENT>> startObjectField(SerializableString fieldName) throws IOException, JsonProcessingException { _closeChild(); _generator.writeFieldName(fieldName); return _startObject(this, _generator); }
Example #13
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 5 votes |
public static EnumValues constructFromToString(MapperConfig<?> config, Class<Enum<?>> enumClass) { Class<? extends Enum<?>> cls = ClassUtil.findEnumType(enumClass); Enum<?>[] values = cls.getEnumConstants(); if (values != null) { SerializableString[] textual = new SerializableString[values.length]; for (Enum<?> en : values) { textual[en.ordinal()] = config.compileString(en.toString()); } return new EnumValues(enumClass, textual); } throw new IllegalArgumentException("Cannot determine enum constants for Class "+enumClass.getName()); }
Example #14
Source File: ObjectIdWriter.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Factory method called by {@link com.fasterxml.jackson.databind.ser.std.BeanSerializerBase} * with the initial information based on standard settings for the type * for which serializer is being built. * * @since 2.3 */ public static ObjectIdWriter construct(JavaType idType, PropertyName propName, ObjectIdGenerator<?> generator, boolean alwaysAsId) { String simpleName = (propName == null) ? null : propName.getSimpleName(); SerializableString serName = (simpleName == null) ? null : new SerializedString(simpleName); return new ObjectIdWriter(idType, serName, generator, null, alwaysAsId); }
Example #15
Source File: ObjectIdWriter.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") protected ObjectIdWriter(JavaType t, SerializableString propName, ObjectIdGenerator<?> gen, JsonSerializer<?> ser, boolean alwaysAsId) { idType = t; propertyName = propName; generator = gen; serializer = (JsonSerializer<Object>) ser; this.alwaysAsId = alwaysAsId; }
Example #16
Source File: MapComposer.java From jackson-jr with Apache License 2.0 | 4 votes |
public CollectionComposer<MapComposer<PARENT>,?> startArrayField(SerializableString fieldName) { return startArrayField(fieldName.getValue()); }
Example #17
Source File: MapComposer.java From jackson-jr with Apache License 2.0 | 4 votes |
public MapComposer<MapComposer<PARENT>> startObjectField(SerializableString fieldName) { return startObjectField(fieldName.getValue()); }
Example #18
Source File: PropertyFilteringJsonGenerator.java From jackson-jaxrs-propertyfiltering with Apache License 2.0 | 4 votes |
@Override public void writeRaw(SerializableString text) throws IOException { if (itemFilter != null) { delegate.writeRaw(text); } }
Example #19
Source File: PropertyFilteringJsonGenerator.java From jackson-jaxrs-propertyfiltering with Apache License 2.0 | 4 votes |
@Override public void writeString(SerializableString value) throws IOException { if (itemFilter != null) { delegate.writeString(value); } }
Example #20
Source File: JsonEncoder.java From metafacture-core with Apache License 2.0 | 4 votes |
public void setPrettyPrinting(final boolean prettyPrinting) { jsonGenerator.setPrettyPrinter(prettyPrinting ? new DefaultPrettyPrinter((SerializableString) null) : null); }
Example #21
Source File: JacksonService.java From agrest with Apache License 2.0 | 4 votes |
public JacksonService() { // fun Jackson API with circular dependencies ... so we create a mapper // first, and grab implicitly created factory from it this.sharedMapper = new ObjectMapper(); this.sharedFactory = sharedMapper.getFactory(); final SerializableString LINE_SEPARATOR = new SerializedString("\\u2028"); final SerializableString PARAGRAPH_SEPARATOR = new SerializedString("\\u2029"); this.sharedFactory.setCharacterEscapes(new CharacterEscapes() { private static final long serialVersionUID = 3995801066651016289L; @Override public int[] getEscapeCodesForAscii() { return standardAsciiEscapesForJSON(); } @Override public SerializableString getEscapeSequence(int ch) { // see ECMA-262 Section 7.3; // in most cases our client is browser, // and JSON is parsed into JS; // therefore these two whitespace characters, // which are perfectly valid in JSON but invalid in JS strings, // need to be escaped... switch (ch) { case '\u2028': return LINE_SEPARATOR; case '\u2029': return PARAGRAPH_SEPARATOR; default: return null; } } }); // make sure mapper does not attempt closing streams it does not // manage... why is this even a default in jackson? sharedFactory.disable(Feature.AUTO_CLOSE_TARGET); // do not flush every time. why would we want to do that? // this is having a HUGE impact on extrest serializers (5x speedup) sharedMapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE); }
Example #22
Source File: ObjectMapperFactory.java From etf-webapp with European Union Public License 1.2 | 4 votes |
@Override public SerializableString getEscapeSequence(int ch) { return new SerializedString("\\u" + String.format("%04x", ch)); }
Example #23
Source File: DocumentGenerator.java From ojai with Apache License 2.0 | 4 votes |
@Override public void writeString(SerializableString value) throws IOException { writeString(value.getValue()); }
Example #24
Source File: DocumentGenerator.java From ojai with Apache License 2.0 | 4 votes |
@Override public void writeFieldName(SerializableString fieldName) throws IOException { currFieldName = fieldName.getValue(); }
Example #25
Source File: JsonParserDecorator.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Override public boolean nextFieldName(final SerializableString str) throws IOException { return jsonParser.nextFieldName(str); }
Example #26
Source File: DescribeSchemaHandler.java From Bats with Apache License 2.0 | 4 votes |
@Override public SerializableString getEscapeSequence(int i) { // no further escaping (beyond ASCII chars) needed return null; }
Example #27
Source File: RawValue.java From lams with GNU General Public License v2.0 | 4 votes |
public RawValue(SerializableString v) { _value = v; }
Example #28
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 4 votes |
public Collection<SerializableString> values() { return Arrays.asList(_textual); }
Example #29
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 4 votes |
public SerializableString serializedValueFor(Enum<?> key) { return _textual[key.ordinal()]; }
Example #30
Source File: EnumValues.java From lams with GNU General Public License v2.0 | 4 votes |
private EnumValues(Class<Enum<?>> enumClass, SerializableString[] textual) { _enumClass = enumClass; _values = enumClass.getEnumConstants(); _textual = textual; }