I'm trying to test vertx mapping between JsonObject and a pojo. I added methods fromJson
and toJson
which will be added to json-mappers.properties. for use in vertx. The class is immutable and using lombok @Value
and @Builder
.
@Value
@Jacksonized
@Builder
public class AdSystem {
String version;
String system;
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
public Optional<String> getSystem() {
return Optional.ofNullable(system);
}
public JsonObject toJson() {
return JsonObject.mapFrom(this);
}
public static AdSystem fromJson(JsonObject jsonObject) {
return jsonObject.mapTo(AdSystem.class);
}
}
When I test this deserialization works but serialization does not.
@Test
public void toJson_passes() {
var system = new AdSystem("1", "iabtechlab");
var json = system.toJson();
assertThat(json).isEqualTo(new JsonObject().put("version", "1").put("system", "iabtechlab"));
}
@Test
public void fromJson_passes() {
var json = new JsonObject().put("version", "1").put("system", "iabtechlab");
var system = AdSystem.fromJson(json);
assertThat(system).isEqualTo(new AdSystem("1", "iabtechlab"));
}
toJson
fails and this is the result.
org.junit.ComparisonFailure:
Expected :{"version":"1","system":"iabtechlab"}
Actual :{"version":{"empty":false,"present":true},"system":{"empty":false,"present":true}}
What am I doing wrong?