It appears that embedded resource field names are not being converted correctly when using a custom naming strategy. Only 'non-HAL' fields are being converted.
Is there a way to ensure custom naming conventions are applied to embedded resources and not just regular fields?
I have the following Gson configuration in a custom MessageBodyWriter...
GsonBuilder builder = new GsonBuilder();
builder.setFieldNamingStrategy(new AllLowercaseFieldNamingStrategy());
builder.registerTypeAdapter(HalResource.class, new HalSerializer());
builder.setExclusionStrategies(new HalExclusionStrategy());
Gson gson = builder.create();
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream)) {
writer.write(gson.toJson(resource, HalResource.class));
}
The AllLowercaseFieldNamingStrategy implementation simply converts the field name to lowercase like so @Override public String translateName(Field f) { return f.getName().toLowerCase(); }
For example:
public class MyResource implements HalResource {
private final String myField;
private final MyResource myEmbeddedResource;
...
}
results in inconsistent field names (should be all lower case based on naming strategy)...
{
"myfield": "...",
"_embedded": {
"myEmbeddedResource": {...}
}
}
It appears that embedded resource field names are not being converted correctly when using a custom naming strategy. Only 'non-HAL' fields are being converted.
Is there a way to ensure custom naming conventions are applied to embedded resources and not just regular fields?
I have the following Gson configuration in a custom MessageBodyWriter...
The
AllLowercaseFieldNamingStrategyimplementation simply converts the field name to lowercase like so@Override public String translateName(Field f) { return f.getName().toLowerCase(); }For example:
results in inconsistent field names (should be all lower case based on naming strategy)...