ObjectMapper getObjectMapper() { ObjectMapper objectMapper = ObjectMapperBuilder.buildNewObjectMapper(); // objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); SimpleModule module = new SimpleModule(); module.addSerializer(BigDecimal.class, new ToStringSerializer()); module.addSerializer(Long.class, new ToStringSerializer()); objectMapper.registerModule(module); //Disable JsonIdentityInfo JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() { @Override public ObjectIdInfo findObjectIdInfo(Annotated ann) { return null; } }; objectMapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector); return objectMapper; }
/** * Build the web services to use and assign them to the application state. */ protected void buildWebServices() { // Build an ObjectMapper for everyone to use, since they are heavy-weight ObjectMapper mapper = new ObjectMapper(); JodaModule jodaModule = new JodaModule(); jodaModule.addSerializer(Interval.class, new ToStringSerializer()); mapper.registerModule(jodaModule); // This alternate switched implementation approach is not really used anywhere, should be split off into a // separate subclass if needed if (state.webService == null) { state.webService = useTestWebService ? new TestDruidWebService("Test UI WS") : new AsyncDruidWebServiceImpl(DruidClientConfigHelper.getServiceConfig(), mapper); } if (state.metadataWebService == null) { state.metadataWebService = (useTestWebService) ? new TestDruidWebService("Test Metadata WS") : new AsyncDruidWebServiceImpl(DruidClientConfigHelper.getMetadataServiceConfig(), mapper); } }
protected final JsonSerializer<?> findSerializerByPrimaryType(SerializerProvider paramSerializerProvider, JavaType paramJavaType, BeanDescription paramBeanDescription, boolean paramBoolean) { Class localClass = paramJavaType.getRawClass(); if (InetAddress.class.isAssignableFrom(localClass)) return InetAddressSerializer.instance; if (TimeZone.class.isAssignableFrom(localClass)) return TimeZoneSerializer.instance; if (Charset.class.isAssignableFrom(localClass)) return ToStringSerializer.instance; JsonSerializer localJsonSerializer = findOptionalStdSerializer(paramSerializerProvider, paramJavaType, paramBeanDescription, paramBoolean); if (localJsonSerializer != null) return localJsonSerializer; if (Number.class.isAssignableFrom(localClass)) return NumberSerializers.NumberSerializer.instance; if (Enum.class.isAssignableFrom(localClass)) return buildEnumSerializer(paramSerializerProvider.getConfig(), paramJavaType, paramBeanDescription); if (Calendar.class.isAssignableFrom(localClass)) return CalendarSerializer.instance; if (java.util.Date.class.isAssignableFrom(localClass)) return DateSerializer.instance; return null; }
@Bean public Module facilityModule() { return new SimpleModule("geometryModule") {{ final JsonMapper jsonMapper = new JsonMapper(); addSerializer(Geometry.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Geometry.class, new GeojsonDeserializer<>(jsonMapper, Geometry.class)); addSerializer(Polygon.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Polygon.class, new GeojsonDeserializer<>(jsonMapper, Polygon.class)); addSerializer(Point.class, new GeojsonSerializer<>(jsonMapper)); addDeserializer(Point.class, new GeojsonDeserializer<>(jsonMapper, Point.class)); addSerializer(Feature.class, new GeojsonSerializer<>(jsonMapper)); addSerializer(Phone.class, new PhoneSerializer()); addSerializer(Time.class, new ToStringSerializer()); }}; }
TestModule() { addSerializer(Interval.class, ToStringSerializer.instance); addDeserializer( Interval.class, new StdDeserializer<Interval>(Interval.class) { @Override public Interval deserialize( JsonParser jsonParser, DeserializationContext deserializationContext ) throws IOException, JsonProcessingException { return new Interval(jsonParser.getText()); } } ); }
private DataModule() { addSerializer(Events.class, new EventsSerializer()); addSerializer(DataMessage.class, new DataMessageSerializer()); addSerializer(CandleSymbol.class, new ToStringSerializer()); addSerializer(IndexedEventSource.class, new ToStringSerializer()); addSerializer(char.class, new NullSafeCharSerializer()); }
/** * Get the IP Address for the switch * @return the inet address */ @Override @JsonSerialize(using=ToStringSerializer.class) public SocketAddress getInetAddress() { if (channel == null) return null; return channel.getRemoteAddress(); }
/** * No-arg constructor. */ public ObjectMappersSuite() { jsonMapper = new ObjectMapper(); csvMapper = new CsvMapper(); JodaModule jodaModule = new JodaModule(); jodaModule.addSerializer(Interval.class, new ToStringSerializer()); jodaModule.setMixInAnnotation(ShardSpec.class, ShardSpecMixIn.class); jsonMapper.registerModule(jodaModule); jsonMapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(false)); jsonMapper.registerModule(new AfterburnerModule()); }
/** * Configure ObjectMapper. */ public JsonLogFormatter() { objectMapper = new ObjectMapper(); objectMapper.registerModule((new JodaModule()).addSerializer(Interval.class, new ToStringSerializer())); objectMapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(false)); objectMapper.registerModule(new AfterburnerModule()); }
public static ObjectMapper create(boolean indent) { ObjectMapper objectMapper = new ObjectMapper(); // This will cause the objectmapper to not close the underlying output stream objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); objectMapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); objectMapper.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false, MetricFilter.ALL)); SimpleModule module = new SimpleModule(); module.addSerializer(ExtendedMeter.class, new ExtendedMeterSerializer(TimeUnit.SECONDS)); module.addSerializer(BigDecimal.class, new ToStringSerializer()); objectMapper.registerModule(module); if (indent) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } return objectMapper; }
protected final JsonSerializer<?> findSerializerByAddonType(SerializationConfig paramSerializationConfig, JavaType paramJavaType, BeanDescription paramBeanDescription, boolean paramBoolean) { Class localClass = paramJavaType.getRawClass(); if (Iterator.class.isAssignableFrom(localClass)) return buildIteratorSerializer(paramSerializationConfig, paramJavaType, paramBeanDescription, paramBoolean); if (Iterable.class.isAssignableFrom(localClass)) return buildIterableSerializer(paramSerializationConfig, paramJavaType, paramBeanDescription, paramBoolean); if (CharSequence.class.isAssignableFrom(localClass)) return ToStringSerializer.instance; return null; }
public JsonSerializer<?> findSerializer(SerializationConfig paramSerializationConfig, JavaType paramJavaType, BeanDescription paramBeanDescription) { Class localClass = paramJavaType.getRawClass(); if ((Duration.class.isAssignableFrom(localClass)) || (QName.class.isAssignableFrom(localClass))) return ToStringSerializer.instance; if (XMLGregorianCalendar.class.isAssignableFrom(localClass)) return XMLGregorianCalendarSerializer.instance; return null; }
@AdditionalJacksonAnnotation("some_long") @JsonProperty("some_long_string") @JsonSerialize(using=ToStringSerializer.class) Long getSomeLong();
@JsonSerialize(using = ToStringSerializer.class) public ZoneId getTimeZone() { return timeZone; }
@JsonSerialize(using = ToStringSerializer.class) public Locale getLocale() { return locale; }
@JsonSerialize(using = ToStringSerializer.class) public OffsetDateTime getOrigin() { return origin; }
@JsonSerialize(using = ToStringSerializer.class) public ZonedDateTime getTimestamp() { return timestamp; }
/** @return code. */ @JsonProperty("code") @JsonSerialize(using = ToStringSerializer.class) abstract char getCode();
/** * @return Rubriek 3570 Aanduiding inhouding dan wel vermissing Nederlands reisdocument. */ @JsonProperty(RUBRIEK_3570) @JsonSerialize(using = ToStringSerializer.class) abstract char getLo3AanduidingInhoudingOfVermissingReisdocument();
/** * @return Rubriek 7210 Omschrijving van de aangifte adreshouding. */ @JsonProperty(RUBRIEK_7210_OMSCHRIJVING) @JsonSerialize(using = ToStringSerializer.class) abstract char getLo3OmschrijvingAangifteAdreshouding();
@JsonSerialize(using = ToStringSerializer.class) public Office getOffice() { return office; }
/** * @return the path */ @JsonSerialize(using = ToStringSerializer.class) public JsonPointer getPath() { return path; }
/** * @return the from */ @JsonSerialize(using = ToStringSerializer.class) public JsonPointer getFrom() { return from; }
@SupCol(text="归属公司", sort = 10, minWidth="125px") @JsonSerialize(using = ToStringSerializer.class) public Office getOffice() { return office; }
@JsonProperty("entry-number") @JsonSerialize(using = ToStringSerializer.class) public Integer getEntryNumber() { return entryNumber; }
@JsonProperty("index-entry-number") @JsonSerialize(using = ToStringSerializer.class) public Integer getIndexEntryNumber() { return indexEntryNumber; }
public JavaTimeModule() { super(PackageVersion.VERSION); // First deserializers // // Instant variants: addDeserializer(Instant.class, InstantDeserializer.INSTANT); addDeserializer(OffsetDateTime.class, InstantDeserializer.OFFSET_DATE_TIME); addDeserializer(ZonedDateTime.class, InstantDeserializer.ZONED_DATE_TIME); // // Other deserializers addDeserializer(Duration.class, DurationDeserializer.INSTANCE); addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); addDeserializer(LocalDate.class, LocalDateDeserializer.INSTANCE); addDeserializer(LocalTime.class, LocalTimeDeserializer.INSTANCE); addDeserializer(MonthDay.class, MonthDayDeserializer.INSTANCE); addDeserializer(OffsetTime.class, OffsetTimeDeserializer.INSTANCE); addDeserializer(Period.class, JSR310StringParsableDeserializer.PERIOD); addDeserializer(Year.class, YearDeserializer.INSTANCE); addDeserializer(YearMonth.class, YearMonthDeserializer.INSTANCE); addDeserializer(ZoneId.class, JSR310StringParsableDeserializer.ZONE_ID); addDeserializer(ZoneOffset.class, JSR310StringParsableDeserializer.ZONE_OFFSET); // then serializers: addSerializer(Duration.class, DurationSerializer.INSTANCE); addSerializer(Instant.class, InstantSerializer.INSTANCE); addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE); addSerializer(LocalDate.class, LocalDateSerializer.INSTANCE); addSerializer(LocalTime.class, LocalTimeSerializer.INSTANCE); addSerializer(MonthDay.class, MonthDaySerializer.INSTANCE); 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); /* 27-Jun-2015, tatu: This is the real difference from the old * {@link JSR310Module}: default is to produce ISO-8601 compatible * serialization with timezone offset only, not timezone id. * But this is configurable. */ addSerializer(ZonedDateTime.class, ZonedDateTimeSerializer.INSTANCE); // note: actual concrete type is `ZoneRegion`, but that's not visible: addSerializer(ZoneId.class, new ToStringSerializer(ZoneId.class)); addSerializer(ZoneOffset.class, new ToStringSerializer(ZoneOffset.class)); // key serializers addKeySerializer(ZonedDateTime.class, ZonedDateTimeKeySerializer.INSTANCE); // key deserializers addKeyDeserializer(Duration.class, DurationKeyDeserializer.INSTANCE); addKeyDeserializer(Instant.class, InstantKeyDeserializer.INSTANCE); addKeyDeserializer(LocalDateTime.class, LocalDateTimeKeyDeserializer.INSTANCE); addKeyDeserializer(LocalDate.class, LocalDateKeyDeserializer.INSTANCE); addKeyDeserializer(LocalTime.class, LocalTimeKeyDeserializer.INSTANCE); addKeyDeserializer(MonthDay.class, MonthDayKeyDeserializer.INSTANCE); addKeyDeserializer(OffsetDateTime.class, OffsetDateTimeKeyDeserializer.INSTANCE); addKeyDeserializer(OffsetTime.class, OffsetTimeKeyDeserializer.INSTANCE); addKeyDeserializer(Period.class, PeriodKeyDeserializer.INSTANCE); addKeyDeserializer(Year.class, YearKeyDeserializer.INSTANCE); addKeyDeserializer(YearMonth.class, YearMothKeyDeserializer.INSTANCE); addKeyDeserializer(ZonedDateTime.class, ZonedDateTimeKeyDeserializer.INSTANCE); addKeyDeserializer(ZoneId.class, ZoneIdKeyDeserializer.INSTANCE); addKeyDeserializer(ZoneOffset.class, ZoneOffsetKeyDeserializer.INSTANCE); }
@Override @JsonSerialize(contentUsing = ToStringSerializer.class) public List<Interval> getIntervals() { return new ArrayList<>(intervals); }
@JsonSerialize(contentUsing = ToStringSerializer.class) public Collection<Interval> getIntervals() { return intervals; }
@SuppressWarnings("rawtypes") protected void injectJacksonAnnotation(EntityType model) { JsonSerialize jacksonAnnotation = new JsonSerialize() { @Override public Class<? extends Annotation> annotationType() { return JsonSerialize.class; } @Override public Class<? extends JsonSerializer> using() { return ToStringSerializer.class; } @Override public Class<? extends JsonSerializer> contentUsing() { return null; } @Override public Class<? extends JsonSerializer> keyUsing() { return null; } @Override public Class<? extends JsonSerializer> nullsUsing() { return null; } @Override public Class<?> as() { return null; } @Override public Class<?> keyAs() { return null; } @Override public Class<?> contentAs() { return null; } @Override public Typing typing() { return null; } @Override public Class<? extends Converter> converter() { return null; } @Override public Class<? extends Converter> contentConverter() { return null; } @SuppressWarnings("deprecation") @Override public Inclusion include() { return null; } }; for(Property property : model.getProperties()) { if(Long.class.equals(property.getType().getJavaClass())) { property.addAnnotation(jacksonAnnotation); } } }
@JsonProperty("stacktrace") @JsonSerialize(contentUsing = ToStringSerializer.class) StackTraceElement[] getStackTrace();