Skip to content

Commit

Permalink
Fix possible NPE for Asset de-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Reznik committed May 7, 2015
1 parent 1d9f2d5 commit ef40a15
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/com/contentful/java/cda/ResourceTypeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ResourceTypeAdapter(SpaceWrapper spaceWrapper, Map<String, Class<?>> cust
this.httpScheme = httpScheme;
}

@Override public CDAResource deserialize(JsonElement jsonElement, Type type,
public CDAResource deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context) throws JsonParseException {
CDAResource result = null;
JsonObject sys = jsonElement.getAsJsonObject().getAsJsonObject("sys");
Expand Down Expand Up @@ -103,19 +103,22 @@ private CDAAsset deserializeAsset(JsonElement jsonElement, JsonDeserializationCo
JsonObject sys) {
CDAAsset result = new CDAAsset();
setBaseFields(result, sys, jsonElement, context);

Map fileMap = (Map) result.getFields().get("file");
String defaultLocale = spaceWrapper.get().getDefaultLocale();
if (fileMap != null) {
String defaultLocale = spaceWrapper.get().getDefaultLocale();

if (fileMap.containsKey(defaultLocale)) {
Object map = fileMap.get(defaultLocale);
if (fileMap.containsKey(defaultLocale)) {
Object map = fileMap.get(defaultLocale);

if (map instanceof Map) {
fileMap = (Map) map;
if (map instanceof Map) {
fileMap = (Map) map;
}
}
}

result.setUrl(String.format("%s:%s", httpScheme, fileMap.get("url")));
result.setMimeType((String) fileMap.get("contentType"));
result.setUrl(String.format("%s:%s", httpScheme, fileMap.get("url")));
result.setMimeType((String) fileMap.get("contentType"));
}

return result;
}
Expand Down

0 comments on commit ef40a15

Please sign in to comment.