5

I am using Dropwizard 0.8.4 and jackson-datatype-jsr310.

a) Would like to serialise my LocalDateTime to JSON output as DateTimeFormatter.ISO_INSTANT but could not find any clean way to do that (without implementing custom serialising classes), shouldn't this be very standard thing to do with simple annotations?

Currently my code works with:

@JsonProperty
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss'Z'")
@JsonSerialize(using = LocalDateTimeSerializer.class)
public LocalDateTime getTime() {
    ...
}

but that pattern isn't really same as ISO_INSTANT, and as I debugged it a bit, ISO_INSTANT cannot even be presented by a String-pattern.

b) Would I be better off using Joda-Time, that seems to be supported by Dropwizard by default?

c) Is there way to skip serialising Java-field into JSON based on the value (boolean being false)? I tried @JsonFilter and SimpleBeanPropertyFilter but didn't get it to work, and it seems to be deprecated as well. Also @JsonProperty(defaultValue...) didn't seem to work either.

Render
  • 2,199
  • 2
  • 16
  • 14
  • Have you looked into this answer? http://stackoverflow.com/a/29738293/696257 – dkulkarni Dec 01 '15 at 13:27
  • 3
    I did check that yesterday and it seemed complicated, however as I just tried it I did get it working with the Option 2 Json(De)Serializer way, but I wonder isn't this use case very typical? Why doesn't Jackson have default annotations and/or implementations for this? Would I have this same issue with Joda-Time? – Render Dec 01 '15 at 14:53

0 Answers0