private List<MessageTag> createTags(String rawTags, JsonMapper jsonMapper) { try { return jsonMapper.toJavaList(rawTags, MessageTag.class); } catch (FacebookJsonMappingException je) { } // message tags not in Graph API 2.5 format, ignore this exception and try another way try { List<MessageTag> resultList = new ArrayList<>(); JsonObject rawMessageTagsObject = jsonMapper.toJavaObject(rawTags, JsonObject.class); for (String key : rawMessageTagsObject.names()) { String tagArrayString = rawMessageTagsObject.get(key).toString(); resultList.addAll(jsonMapper.toJavaList(tagArrayString, MessageTag.class)); } return resultList; } catch (FacebookJsonMappingException je) { return new ArrayList<>(); } }
private Map convertJsonObjectToMap(String json, Field field) { Class<?> firstParam = getFirstParameterizedTypeArgument(field); if (!String.class.equals(firstParam)) { throw new FacebookJsonMappingException("The java type map needs to have a 'String' key, but is " + firstParam); } Class<?> secondParam = getSecondParameterizedTypeArgument(field); if (json.startsWith("{")) { JsonObject jsonObject = Json.parse(json).asObject(); Map<String, Object> map = new HashMap(); for (String key : jsonObject.names()) { String value = jsonHelper.getStringFrom(jsonObject.get(key)); map.put(key, toJavaObject(value, secondParam)); } return map; } return null; }
@JsonMapper.JsonMappingCompleted private void convertAppRoles() { if (rawAppRoles != null) { AppRoles appRoles = new AppRoles(); for (String appId : rawAppRoles.names()) { List<JsonValue> rawRoles = rawAppRoles.get(appId).asArray().values(); List<String> roles = new ArrayList<>(); for (JsonValue rawValue : rawRoles) { roles.add(rawValue.asString()); } appRoles.addRoles(appId, roles); } this.appRoles = appRoles; } }
@JsonMappingCompleted private void convertList(JsonMapper mapper) { if (rawRegionsString != null) { JsonValue jsonValue = Json.parse(rawRegionsString); if (jsonValue.isObject()) { JsonObject rawRegions = jsonValue.asObject(); for (String key : rawRegions.names()) { String region = rawRegions.get(key).toString(); regions.add(mapper.toJavaObject(region, KeyedType.class)); } } } }
/** * Post-JSON-mapping operation that populates the {@code messageTags} field "by hand". * * @param jsonMapper * The {@code JsonMapper} that was used to map to this type. */ @JsonMappingCompleted protected void jsonMappingCompleted(JsonMapper jsonMapper) { if (rawMessageTags == null) { return; } try { messageTags = jsonMapper.toJavaList(rawMessageTags, MessageTag.class); return; } catch (FacebookJsonMappingException je) { } // message tags not in Graph API 2.5 format, ignore this exception and try another way try { JsonObject rawMessageTagsObject = jsonMapper.toJavaObject(rawMessageTags, JsonObject.class); for (String key : rawMessageTagsObject.names()) { String tagArrayString = rawMessageTagsObject.get(key).toString(); messageTags.addAll(jsonMapper.toJavaList(tagArrayString, MessageTag.class)); } } catch (FacebookJsonMappingException je) { } // cannot parse message tags, but don't break the flow here }
/** * Post-JSON-mapping operation that populates the {@code messageTags} field "by hand". * * @param jsonMapper * The {@code JsonMapper} that was used to map to this type. */ @JsonMappingCompleted protected void jsonMappingCompleted(JsonMapper jsonMapper) { if (rawNameTags == null) { return; } try { nameTags = jsonMapper.toJavaList(rawNameTags, EntityAtTextRange.class); return; } catch (FacebookJsonMappingException je) { } // message tags not in Graph API 2.5 format, ignore this exception and try another way try { JsonObject rawMessageTagsObject = jsonMapper.toJavaObject(rawNameTags, JsonObject.class); for (String key : rawMessageTagsObject.names()) { String tagArrayString = rawMessageTagsObject.get(key).toString(); nameTags.addAll(jsonMapper.toJavaList(tagArrayString, EntityAtTextRange.class)); } } catch (FacebookJsonMappingException je) { } // cannot parse message tags, but don't break the flow here }
List<String> fieldNames = jsonObject.names();
@JsonMapper.JsonMappingCompleted public void convertRawEntites(JsonMapper mapper) { List<String> names = (rawEntities != null) ? rawEntities.names() : Collections.<String> emptyList(); for (String key : names) { if ("datetime".equals(key)) {
if (result.names().isEmpty()) { throw new IllegalArgumentException("unknown rule found"); } else {