Jackson serializes empty guava table as {"empty": true} instead of {}

29 Views Asked by At

I'm trying to serialize and deserialize an empty guava Table<R, C, V> object. The behavior I would expect is something like "table": {}, but what I'm getting is "table": {"empty": true}.

Here's a simplistic failing test that illustrates what I mean:

  @Autowired
  private ObjectMapper mapper;

  @Test
  public void testSerializeEmptyTable() throws Exception {
    Table<String, Locale, String> testTable = HashBasedTable.create();
    String result = mapper.writeValueAsString(testTable);
    Assertions.assertNotNull(result);
    Assertions.assertEquals("{}", result);
  }

Result:

org.opentest4j.AssertionFailedError: 
Expected :{}
Actual   :{"empty":true}

I'm using a custom deserializer for this object (deserialization isn't supported natively as yet, only serialization -- seems odd, but true -- see here)

I suppose I could edit the custom deserializer to handle this case... but that seems like a poor, hack-y workaround. Is there a configuration or something I'm missing somewhere to help resolve this? Or is it perhaps a bug in the serializer?

Here's the dependency in my pom for reference:

    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-guava</artifactId>
    </dependency>
0

There are 0 best solutions below