Java Code Examples for com.fasterxml.jackson.core.SerializableString

The following examples show how to use com.fasterxml.jackson.core.SerializableString. These examples are extracted from open source projects. 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 Project: lams   Source File: WritableObjectId.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 2
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 3
@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 4
Source Project: metafacture-core   Source File: JsonEncoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source Project: lams   Source File: ObjectIdWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 6
Source Project: lams   Source File: ObjectIdWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 7
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 8
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 9
Source Project: lams   Source File: RawValue.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 Project: lams   Source File: RawValue.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void _serialize(JsonGenerator gen) throws IOException
{
    if (_value instanceof SerializableString) {
        gen.writeRawValue((SerializableString) _value);
    } else {
        gen.writeRawValue(String.valueOf(_value));
    }
}
 
Example 11
Source Project: curiostack   Source File: MessageMarshaller.java    License: MIT License 5 votes vote down vote up
@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 12
@Override
public void writeString(final SerializableString text) throws IOException {
  if (text != null && isSensitiveAttribute()) {
    super.writeString(passwordHelper.encrypt(text.getValue()));
  }
  else {
    super.writeString(text);
  }
}
 
Example 13
Source Project: webanno   Source File: JSONUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SerializableString getEscapeSequence(int aCh)
{
    switch (aCh) {
    case '\u2028':
        return new SerializedString("\\u2028");
    case '\u2029':
        return new SerializedString("\\u2029");
    default:
        return null;
    }
}
 
Example 14
Source Project: jackson-jr   Source File: ObjectComposer.java    License: Apache License 2.0 5 votes vote down vote up
public ArrayComposer<ObjectComposer<PARENT>> startArrayField(SerializableString fieldName)
    throws IOException, JsonProcessingException
{
    _closeChild();
    _generator.writeFieldName(fieldName);
    return _startArray(this, _generator);
}
 
Example 15
Source Project: jackson-jr   Source File: ObjectComposer.java    License: Apache License 2.0 5 votes vote down vote up
public ObjectComposer<ObjectComposer<PARENT>> startObjectField(SerializableString fieldName)
    throws IOException, JsonProcessingException
{
    _closeChild();
    _generator.writeFieldName(fieldName);
    return _startObject(this, _generator);
}
 
Example 16
Source Project: Bats   Source File: DescribeSchemaHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SerializableString getEscapeSequence(int i) {
  // no further escaping (beyond ASCII chars) needed
  return null;
}
 
Example 17
Source Project: lams   Source File: BeanPropertyWriter.java    License: GNU General Public License v2.0 4 votes vote down vote up
public SerializableString getSerializedName() {
    return _name;
}
 
Example 18
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 4 votes vote down vote up
private EnumValues(Class<Enum<?>> enumClass, SerializableString[] textual)
{
    _enumClass = enumClass;
    _values = enumClass.getEnumConstants();
    _textual = textual;
}
 
Example 19
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 4 votes vote down vote up
public SerializableString serializedValueFor(Enum<?> key) {
    return _textual[key.ordinal()];
}
 
Example 20
Source Project: lams   Source File: EnumValues.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Collection<SerializableString> values() {
    return Arrays.asList(_textual);
}
 
Example 21
Source Project: lams   Source File: RawValue.java    License: GNU General Public License v2.0 4 votes vote down vote up
public RawValue(SerializableString v) {
    _value = v;
}
 
Example 22
@Override
public SerializableString getEscapeSequence(int ch) {
    return new SerializedString("\\u" + String.format("%04x", ch));
}
 
Example 23
Source Project: nexus-public   Source File: JsonParserDecorator.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean nextFieldName(final SerializableString str) throws IOException {
  return jsonParser.nextFieldName(str);
}
 
Example 24
Source Project: ojai   Source File: DocumentGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void writeFieldName(SerializableString fieldName)
    throws IOException {
  currFieldName = fieldName.getValue();
}
 
Example 25
Source Project: ojai   Source File: DocumentGenerator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void writeString(SerializableString value) throws IOException {
  writeString(value.getValue());
}
 
Example 26
Source Project: agrest   Source File: JacksonService.java    License: Apache License 2.0 4 votes vote down vote up
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 27
@Override
public void writeString(SerializableString value) throws IOException {
  if (itemFilter != null) {
    delegate.writeString(value);
  }
}
 
Example 28
@Override
public void writeRaw(SerializableString text) throws IOException {
  if (itemFilter != null) {
    delegate.writeRaw(text);
  }
}
 
Example 29
Source Project: jackson-jr   Source File: MapComposer.java    License: Apache License 2.0 4 votes vote down vote up
public CollectionComposer<MapComposer<PARENT>,?> startArrayField(SerializableString fieldName) {
    return startArrayField(fieldName.getValue());
}
 
Example 30
Source Project: jackson-jr   Source File: MapComposer.java    License: Apache License 2.0 4 votes vote down vote up
public MapComposer<MapComposer<PARENT>> startObjectField(SerializableString fieldName) {
    return startObjectField(fieldName.getValue());
}