Skip to content

Commit

Permalink
spotless:apply
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaofeiCao committed May 9, 2024
1 parent c64b37b commit 5a71554
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public SubResource withId(String id) {

@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
return jsonWriter.writeStartObject()
.writeStringField("id", id)
.writeEndObject();
return jsonWriter.writeStartObject().writeStringField("id", id).writeEndObject();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ public static SubResourceResource fromJson(JsonReader jsonReader) throws IOExcep
} else if ("subResourceList".equals(fieldName)) {
subResource.withSubResourceList(reader.readArray(reader1 -> SubResource.fromJson(reader1)));
} else if ("subResourceResource".equals(fieldName)) {
subResource.withSubResourceResource(reader.readObject(reader1 -> SubResourceResource.fromJson(reader1)));
subResource.withSubResourceResource(
reader.readObject(reader1 -> SubResourceResource.fromJson(reader1)));
} else if ("subResourceResourceList".equals(fieldName)) {
subResource.withSubResourceResourceList(reader.readArray(reader1 -> SubResourceResource.fromJson(reader1)));
subResource.withSubResourceResourceList(
reader.readArray(reader1 -> SubResourceResource.fromJson(reader1)));
} else {
reader.skipChildren();
}
Expand Down Expand Up @@ -294,18 +296,20 @@ public void testSerialization() throws IOException {
SubResourceResource subResourceResourceRoot = new SubResourceResource();
SubResource subResource = new SubResource().withId(UUID.randomUUID().toString());
SubResourceResource subResourceResourceNest = new SubResourceResource().withId(UUID.randomUUID().toString());
subResourceResourceRoot
.withSubResource(subResource)
subResourceResourceRoot.withSubResource(subResource)
.withSubResourceList(Collections.singletonList(subResource))
.withSubResourceResource(subResourceResourceNest)
.withSubResourceResourceList(Collections.singletonList(subResourceResourceNest));

String json = serializeToString(subResourceResourceRoot);
SubResourceResource subResourceResourceRootDeserialized = deserialize(json, SubResourceResource::fromJson);
Assertions.assertEquals(subResource.id(), subResourceResourceRootDeserialized.subResource().id());
Assertions.assertEquals(subResource.id(), subResourceResourceRootDeserialized.subResourceList().iterator().next().id());
Assertions.assertEquals(subResourceResourceNest.id(), subResourceResourceRootDeserialized.subResourceResource().id());
Assertions.assertEquals(subResourceResourceNest.id(), subResourceResourceRootDeserialized.subResourceResourceList().iterator().next().id());
Assertions.assertEquals(subResource.id(),
subResourceResourceRootDeserialized.subResourceList().iterator().next().id());
Assertions.assertEquals(subResourceResourceNest.id(),
subResourceResourceRootDeserialized.subResourceResource().id());
Assertions.assertEquals(subResourceResourceNest.id(),
subResourceResourceRootDeserialized.subResourceResourceList().iterator().next().id());
}

private static <T extends JsonSerializable<T>> String serializeToString(T serializable) throws IOException {
Expand Down

0 comments on commit 5a71554

Please sign in to comment.