Skip to content

Commit

Permalink
Fixed ERRAI-802: Jackson (de)marshalling fails for collections of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek committed Oct 6, 2014
1 parent 86d76d4 commit e57d2a3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Expand Up @@ -141,6 +141,7 @@ else if (k.equals(ENUM_STRING_VALUE) || k.equals(NUMERIC_VALUE)) {
if (parent != null) {
parent.put(key, obj.get(k));
}
return toJackson(obj.get(k), k, obj, objectCache);
}
else if (k.equals(QUALIFIED_VALUE)) {
if (parent != null) {
Expand Down Expand Up @@ -174,7 +175,7 @@ else if (k.startsWith(SerializationParts.EMBEDDED_JSON)) {
}
}

return cleanUpEmbeddedJson(obj);
return (obj != null) ? cleanUpEmbeddedJson(obj) : val;
}

private static JSONObject cleanUpEmbeddedJson(JSONObject obj) {
Expand Down
Expand Up @@ -53,6 +53,16 @@ public enum Gender {

private Map<Integer, String> friendsNameMap = new HashMap<Integer, String>();
private Map<String, User> friendsMap = new HashMap<String, User>();

private List<Gender> genders;

public List<Gender> getGenders() {
return genders;
}

public void setGenders(List<Gender> genders) {
this.genders = genders;
}

private Integer age;
private boolean alive = true;
Expand Down Expand Up @@ -263,6 +273,12 @@ else if (!friends.equals(other.friends))
}
else if (!friendsMap.equals(other.friendsMap))
return false;
if (genders == null) {
if (other.genders != null)
return false;
}
else if (!genders.equals(other.genders))
return false;
if (friendsNameMap == null) {
if (other.friendsNameMap != null)
return false;
Expand Down
Expand Up @@ -99,8 +99,14 @@ public void testJacksonMarshalling() {
put("friend2-first", friend2);
}
});

List<Gender> genders = new ArrayList<Gender>();
genders.add(Gender.MALE);
genders.add(Gender.FEMALE);
user.setGenders(genders);

String jackson = MarshallingWrapper.toJSON(user);

call(JacksonTestService.class,
new RemoteCallback<String>() {
@Override
Expand Down
Expand Up @@ -72,12 +72,15 @@ protected <T extends Collection<Object>> T marshallToCollection(final T collecti
type = assumedElementType;
}
}
else {
type = assumedElementType;
}

if (type == null) {
type = ctx.determineTypeFor(null, elem);
}

// the assumed element type can only be used once since they it is not set for nested collections.
// the assumed element type can only be used once since it is not set for nested collections.
ctx.setAssumedElementType(null);
final Marshaller<Object> marshallerInstance = ctx.getMarshallerInstance(type);
if (marshallerInstance == null) {
Expand Down

0 comments on commit e57d2a3

Please sign in to comment.