Skip to content

Commit

Permalink
[Enhancement #43] Order attributes for serialization so that object p…
Browse files Browse the repository at this point in the history
…roperty values are processed last to prevent issues with context building.
  • Loading branch information
ledsoft committed Feb 8, 2023
1 parent 7af55ee commit bf18fde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ private static List<Field> getMarshallableFields(Class<?> cls, Predicate<Field>
}
}
}
return new ArrayList<>(fields);
final List<Field> result = new ArrayList<>(fields);
// Move object properties to the end
result.sort(Comparator.comparing(BeanAnnotationProcessor::isObjectProperty));
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,9 @@ void serializationCreatesEmbeddedContextToOverrideIncompatibleTermMapping() thro
assertInstanceOf(Map.class, json.get(JsonLd.CONTEXT));
final Map<String, ?> context = (Map<String, JsonNode>) json.get(JsonLd.CONTEXT);
assertEquals(DC.Terms.TITLE, context.get("name"));
assertThat(json, hasKey(JsonLd.GRAPH));
assertInstanceOf(Map.class, json.get(JsonLd.GRAPH));
final Map<String, ?> study = (Map<String, JsonNode>) json.get(JsonLd.GRAPH);
assertThat(study, hasKey("organization"));
assertInstanceOf(Map.class, study.get("organization"));
final Map<String, ?> organization = (Map<String, ?>) study.get("organization");
assertThat(json, hasKey("organization"));
assertInstanceOf(Map.class, json.get("organization"));
final Map<String, ?> organization = (Map<String, ?>) json.get("organization");
assertThat(organization, hasKey(JsonLd.CONTEXT));
assertInstanceOf(Map.class, organization.get(JsonLd.CONTEXT));
final Map<String, ?> embeddedCtx = (Map<String, ?>) organization.get(JsonLd.CONTEXT);
Expand Down

0 comments on commit bf18fde

Please sign in to comment.