-
Notifications
You must be signed in to change notification settings - Fork 52
Unable to Serialize RangeSet using asRanges() method after upgrading to jackson 2.8 #93
Comments
Exception message indicates that you have not added Java 8 date/time module ( If this is not enough, I would need a test case to reproduce the behavior. Also: now that 2.9.0 is out, it would make sense to test with that; or, if using 2.8, make sure to use the latest patch version (2.8.9). |
Hi cowtowncoder, public class RangeInterval {
private RangeSet<LocalDateTime> rangeSet;
public RangeInterval() {
rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(LocalDateTime.now().minusDays(5), LocalDateTime.now()));
rangeSet.add(Range.closed(LocalDateTime.now().minusDays(10), LocalDateTime.now().minusDays(8)));
}
public Set<Range<LocalDateTime>> getRangeSet() {
return rangeSet.asRanges();
}
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new GuavaModule());
mapper.registerModule(new JavaTimeModule());
System.out.println(mapper.writeValueAsString(new RangeInterval()));
}
} |
And just to make sure: are you using |
I am using Can this create dependency issues? If yes can you explain me? |
@nisarakash Yes, it could cause issues: minor versions of components should match. Often some combinations of "close enough" minor versions do work, and I can't say for sure this is what is causing problems, but I would try upgrading all components to 2.8.9. Note, too, that Jackson releases always use patch version, so while I sometimes refer to |
Hi,
I am trying to serialize RangeSet using jackson 2.8 libraries. I am getting the following exception:
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.time.LocalDateTime and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.akash.test.Range.RangeInterval["rangeSet"]->com.google.common.collect.TreeRangeSet$AsRanges[0])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:284)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1110)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1135)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.datatype.guava.ser.RangeSerializer._writeContents(RangeSerializer.java:133)
at com.fasterxml.jackson.datatype.guava.ser.RangeSerializer.serialize(RangeSerializer.java:90)
at com.fasterxml.jackson.datatype.guava.ser.RangeSerializer.serialize(RangeSerializer.java:20)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContentsUsing(CollectionSerializer.java:176)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:120)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:112)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:704)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:689)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3697)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3073)
at com.akash.test.Range.RangeInterval.main(RangeInterval.java:38)
As per my understanding, it is trying to access the first element (i.e. TreeRangeSet$AsRanges[0]) of the set using index which I guess is not a valid option in the set.
It works great with jackson 2.6 libraries. Can anyone help me out?
The text was updated successfully, but these errors were encountered: