@Override public void configureObjectMapper(ObjectMapper objectMapper) { super.configureObjectMapper(objectMapper); SimpleModule module = new SimpleModule(); module.addSerializer(BigDecimal.class, new ToStringSerializer()); objectMapper.registerModule(module); } });
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator g, SerializerProvider provider, TypeSerializer typeSer) throws IOException { WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, typeSer.typeId(value, JsonToken.VALUE_STRING)); serialize(value, g, provider); typeSer.writeTypeSuffix(g, typeIdDef); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return createSchemaNode("string", true); }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { visitStringFormat(visitor, typeHint); } }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { visitStringFormat(visitor, typeHint); } }
sers.put(java.net.URL.class, new ToStringSerializer(java.net.URL.class)); sers.put(java.net.URI.class, new ToStringSerializer(java.net.URI.class)); sers.put(Currency.class, new ToStringSerializer(Currency.class)); sers.put(UUID.class, new UUIDSerializer()); sers.put(java.util.regex.Pattern.class, new ToStringSerializer(java.util.regex.Pattern.class)); sers.put(Locale.class, new ToStringSerializer(Locale.class));
public class TryJsonStringSerializer extends JsonSerializer<String> { private RawSerializer<String> rawSerializer = new RawSerializer<String>(String.class); private ToStringSerializer stringSerializer = ToStringSerializer.instance; @Override public void serialize(String value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { if (value == null) { return; } value = value.trim(); if (value.startsWith("{") && value.endsWith("}")) { rawSerializer.serialize(value, jsonGenerator, serializerProvider); } else { stringSerializer.serialize(value, jsonGenerator, serializerProvider); } } }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return createSchemaNode("string", true); }
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { visitStringFormat(visitor, typeHint); } }
SimpleModule module = new SimpleModule(); module.addSerializer(BigInteger.class, new ToStringSerializer()); objectMapper.registerModule(module);
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return createSchemaNode("string", true); }
addSerializer(OffsetDateTime.class, OffsetDateTimeSerializer.INSTANCE); addSerializer(OffsetTime.class, OffsetTimeSerializer.INSTANCE); addSerializer(Period.class, new ToStringSerializer(Period.class)); addSerializer(Year.class, YearSerializer.INSTANCE); addSerializer(YearMonth.class, YearMonthSerializer.INSTANCE); addSerializer(ZoneId.class, new ToStringSerializer(ZoneId.class)); addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class));
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException { typeSer.writeTypePrefixForScalar(value, jgen); serialize(value, jgen, provider); typeSer.writeTypeSuffixForScalar(value, jgen); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return createSchemaNode("string", true); }
addSerializer(OffsetDateTime.class, OffsetDateTimeSerializer.INSTANCE); addSerializer(OffsetTime.class, OffsetTimeSerializer.INSTANCE); addSerializer(Period.class, new ToStringSerializer(Period.class)); addSerializer(Year.class, YearSerializer.INSTANCE); addSerializer(YearMonth.class, YearMonthSerializer.INSTANCE); addSerializer(ZoneId.class, new ToStringSerializer(ZoneId.class)); addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class));
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }
@Override public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { return createSchemaNode("string", true); }
@Bean public SimpleModule objectIdModule() { SimpleModule module = new SimpleModule(); module.addSerializer(ObjectId.class, new ToStringSerializer()); return module; }
/** * Default implementation will write type prefix, call regular serialization * method (since assumption is that value itself does not need JSON * Array or Object start/end markers), and then write type suffix. * This should work for most cases; some sub-classes may want to * change this behavior. */ @Override public void serializeWithType(Object value, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer) throws IOException { typeSer.writeTypePrefixForScalar(value, gen); serialize(value, gen, provider); typeSer.writeTypeSuffixForScalar(value, gen); }