Skip to content

Commit

Permalink
Code Review Changes
Browse files Browse the repository at this point in the history
1. Renamed badname to primary-name
2. Added test deserializing TranslateName with translateToAlternateNames
  • Loading branch information
mfriesen committed Nov 21, 2024
1 parent c9e39dd commit 705e97b
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,29 @@ public void testAtSignInSerializedName() {
assertThat(new Gson().toJson(new AtName())).isEqualTo("{\"@foo\":\"bar\"}");
}

@Test
public void testGsonWithNameDeserialiation() {
Gson gson =
builder
.setFieldNamingStrategy(
new FieldNamingStrategy() {

@Override
public String translateName(Field f) {
return "SomeConstantStringInstanceField";
}

@Override
public List<String> translateToAlternateNames(Field f) {
return List.of("alternate-name");
}
})
.create();
String target = "{\"SomeConstantStringInstanceField\":\"someValue\"}";
StringWrapper deserializedObject = gson.fromJson(target, StringWrapper.class);
assertThat(deserializedObject.someConstantStringInstanceField).isEqualTo("someValue");
}

@Test
public void testGsonWithAlternateNamesDeserialiation() {
Gson gson =
Expand All @@ -247,7 +270,7 @@ public void testGsonWithAlternateNamesDeserialiation() {

@Override
public String translateName(Field f) {
return "badname";
return "primary-name";
}

@Override
Expand Down

0 comments on commit 705e97b

Please sign in to comment.