Java Code Examples for com.fasterxml.jackson.annotation.JsonFormat.Shape#STRING
The following examples show how to use
com.fasterxml.jackson.annotation.JsonFormat.Shape#STRING .
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: EnumSerializer.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Helper method called to check whether serialization should be done using * index (number) or not. */ protected static Boolean _isShapeWrittenUsingIndex(Class<?> enumClass, JsonFormat.Value format, boolean fromClass, Boolean defaultValue) { JsonFormat.Shape shape = (format == null) ? null : format.getShape(); if (shape == null) { return defaultValue; } // i.e. "default", check dynamically if (shape == Shape.ANY || shape == Shape.SCALAR) { return defaultValue; } // 19-May-2016, tatu: also consider "natural" shape if (shape == Shape.STRING || shape == Shape.NATURAL) { return Boolean.FALSE; } // 01-Oct-2014, tatu: For convenience, consider "as-array" to also mean 'yes, use index') if (shape.isNumeric() || (shape == Shape.ARRAY)) { return Boolean.TRUE; } // 07-Mar-2017, tatu: Also means `OBJECT` not available as property annotation... throw new IllegalArgumentException(String.format( "Unsupported serialization shape (%s) for Enum %s, not supported as %s annotation", shape, enumClass.getName(), (fromClass? "class" : "property"))); }
Example 2
Source File: JSR310FormattedSerializerBase.java From jackson-modules-java8 with Apache License 2.0 | 6 votes |
protected boolean useTimestamp(SerializerProvider provider) { if (_useTimestamp != null) { return _useTimestamp.booleanValue(); } if (_shape != null) { if (_shape == Shape.STRING) { return false; } if (_shape == Shape.NUMBER_INT) { return true; } } // assume that explicit formatter definition implies use of textual format return (_formatter == null) && (provider != null) && provider.isEnabled(getTimestampsFeature()); }
Example 3
Source File: BaseDateJsonSerializer.java From domino-jackson with Apache License 2.0 | 5 votes |
@Override protected void doSerialize(JsonWriter writer, Date value, JsonSerializationContext ctx, JsonSerializerParameters params) { if ((ctx.isWriteDatesAsTimestamps() || params.getShape().isNumeric()) && params.getShape() != Shape.STRING) { writer.value(value.getTime()); } else { String date = JacksonContextProvider.get().dateFormat().format(params, value); if (null == params.getPattern()) { writer.unescapeValue(date); } else { writer.value(date); } } }
Example 4
Source File: BaseDateJsonSerializer.java From gwt-jackson with Apache License 2.0 | 5 votes |
@Override protected void doSerialize( JsonWriter writer, Date value, JsonSerializationContext ctx, JsonSerializerParameters params ) { if ( (ctx.isWriteDatesAsTimestamps() || params.getShape().isNumeric()) && params.getShape() != Shape.STRING ) { writer.value( value.getTime() ); } else { String date = DateFormat.format( params, value ); if ( null == params.getPattern() ) { writer.unescapeValue( date ); } else { writer.value( date ); } } }
Example 5
Source File: JsonFormatTester.java From gwt-jackson with Apache License 2.0 | 4 votes |
public FormatDateBean( @JsonProperty( "dateInParameter" ) @JsonFormat( shape = Shape.STRING, pattern = "'P'yyyy/MM/dd" ) Date dateParameter ) { this.dateInParameter = dateParameter; }