com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor Java Examples
The following examples show how to use
com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor.
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: JsonValueSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Overridable helper method used for special case handling of schema information for * Enums. * * @return True if method handled callbacks; false if not; in latter case caller will * send default callbacks * * @since 2.6 */ protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visitor, JavaType typeHint, Class<?> enumType) throws JsonMappingException { // Copied from EnumSerializer#acceptJsonFormatVisitor JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint); if (stringVisitor != null) { Set<String> enums = new LinkedHashSet<String>(); for (Object en : enumType.getEnumConstants()) { try { // 21-Apr-2016, tatu: This is convoluted to the max, but essentially we // call `@JsonValue`-annotated accessor method on all Enum members, // so it all "works out". To some degree. enums.add(String.valueOf(_accessor.getValue(en))); } catch (Exception e) { Throwable t = e; while (t instanceof InvocationTargetException && t.getCause() != null) { t = t.getCause(); } ClassUtil.throwIfError(t); throw JsonMappingException.wrapWithPath(t, en, _accessor.getName() + "()"); } } stringVisitor.enumTypes(enums); } return true; }
Example #2
Source File: EnumSerializer.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { SerializerProvider serializers = visitor.getProvider(); if (_serializeAsIndex(serializers)) { visitIntFormat(visitor, typeHint, JsonParser.NumberType.INT); return; } JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint); if (stringVisitor != null) { Set<String> enums = new LinkedHashSet<String>(); // Use toString()? if ((serializers != null) && serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) { for (Enum<?> e : _values.enums()) { enums.add(e.toString()); } } else { // No, serialize using name() or explicit overrides for (SerializableString value : _values.values()) { enums.add(value.getValue()); } } stringVisitor.enumTypes(enums); } }
Example #3
Source File: YearMonthSerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Override protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { SerializerProvider provider = visitor.getProvider(); boolean useTimestamp = (provider != null) && useTimestamp(provider); if (useTimestamp) { super._acceptTimestampVisitor(visitor, typeHint); } else { JsonStringFormatVisitor v2 = visitor.expectStringFormat(typeHint); if (v2 != null) { v2.format(JsonValueFormat.DATE_TIME); } } }
Example #4
Source File: LocalTimeSerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { if (useTimestamp(visitor.getProvider())) { _acceptTimestampVisitor(visitor, typeHint); } else { JsonStringFormatVisitor v2 = visitor.expectStringFormat(typeHint); if (v2 != null) { v2.format(JsonValueFormat.TIME); } } }
Example #5
Source File: LocalDateSerializer.java From jackson-modules-java8 with Apache License 2.0 | 5 votes |
@Override public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException { SerializerProvider provider = visitor.getProvider(); boolean useTimestamp = (provider != null) && useTimestamp(provider); if (useTimestamp) { _acceptTimestampVisitor(visitor, typeHint); } else { JsonStringFormatVisitor v2 = visitor.expectStringFormat(typeHint); if (v2 != null) { v2.format(JsonValueFormat.DATE); } } }
Example #6
Source File: FieldDocumentationVisitorWrapper.java From spring-auto-restdocs with Apache License 2.0 | 4 votes |
@Override public JsonStringFormatVisitor expectStringFormat(JavaType type) throws JsonMappingException { addFieldIfPresent("String"); return new JsonStringFormatVisitor.Base(); }