List of usage examples for com.fasterxml.jackson.databind JsonMappingException JsonMappingException
public JsonMappingException(String paramString)
From source file:com.basho.riak.client.raw.http.ConversionUtil.java
/** * Copy the data from a {@link BucketResponse} into a * {@link BucketProperties}//from w w w . j a v a 2 s. c o m * * @param response * the {@link BucketResponse} to copy * @return a {@link BucketProperties} populated from <code>response</code> */ static BucketProperties convert(BucketResponse response) throws IOException { String schema = response.getBodyAsString(); JsonNode root = OBJECT_MAPPER.readValue(schema, JsonNode.class); BucketPropertiesBuilder builder = new BucketPropertiesBuilder(); JsonNode props = root.path(Constants.FL_SCHEMA); if (props.isMissingNode()) { throw new JsonMappingException("no 'props' field found"); } builder.allowSiblings(props.path(Constants.FL_SCHEMA_ALLOW_MULT).asBoolean()); builder.lastWriteWins(props.path(Constants.FL_SCHEMA_LAST_WRITE_WINS).asBoolean()); builder.nVal(props.path(Constants.FL_SCHEMA_NVAL).asInt()); builder.backend(props.path(Constants.FL_SCHEMA_BACKEND).textValue()); builder.smallVClock(props.path(Constants.FL_SCHEMA_SMALL_VCLOCK).asInt()); builder.bigVClock(props.path(Constants.FL_SCHEMA_BIG_VCLOCK).asInt()); builder.youngVClock(props.path(Constants.FL_SCHEMA_YOUNG_VCLOCK).asLong()); builder.oldVClock(props.path(Constants.FL_SCHEMA_OLD_VCLOCK).asLong()); for (JsonNode n : props.path(Constants.FL_SCHEMA_PRECOMMIT)) { if (n.path(Constants.FL_SCHEMA_FUN_NAME).isMissingNode()) { builder.addPrecommitHook(OBJECT_MAPPER.treeToValue(n, NamedErlangFunction.class)); } else { builder.addPrecommitHook(OBJECT_MAPPER.treeToValue(n, NamedJSFunction.class)); } } for (JsonNode n : props.path(Constants.FL_SCHEMA_POSTCOMMIT)) { builder.addPostcommitHook(OBJECT_MAPPER.treeToValue(n, NamedErlangFunction.class)); } builder.r(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_R), Quorum.class)); builder.w(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_W), Quorum.class)); builder.dw(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_DW), Quorum.class)); builder.rw(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_RW), Quorum.class)); // TODO backwards compatibility - remove when riak goes 1.3 if (!props.path(Constants.FL_SCHEMA_PR).isMissingNode()) { builder.pr(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_PR), Quorum.class)); } if (!props.path(Constants.FL_SCHEMA_PW).isMissingNode()) { builder.pw(OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_PW), Quorum.class)); } if (!props.path(Constants.FL_SCHEMA_BASIC_QUORUM).isMissingNode()) { builder.basicQuorum(props.path(Constants.FL_SCHEMA_BASIC_QUORUM).asBoolean()); } if (!props.path(Constants.FL_SCHEMA_NOT_FOUND_OK).isMissingNode()) { builder.notFoundOK(props.path(Constants.FL_SCHEMA_NOT_FOUND_OK).asBoolean()); } builder.chashKeyFunction( OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_CHASHFUN), NamedErlangFunction.class)); builder.linkWalkFunction( OBJECT_MAPPER.treeToValue(props.path(Constants.FL_SCHEMA_LINKFUN), NamedErlangFunction.class)); builder.search(props.path(Constants.FL_SCHEMA_SEARCH).asBoolean()); return builder.build(); }
From source file:org.wikidata.wdtk.wikibaseapi.WbEditEntityAction.java
/** * Executes a call to wbeditentity. Minimal error handling. * * @param parameters// w ww .j a va2 s . c o m * the parameters to be used in the call * @return the entity document that is returned, or null in case of errors * @throws IOException * if there were IO errors * @throws MediaWikiApiErrorException * if the API returned an error */ private EntityDocument doWbEditEntity(Map<String, String> parameters) throws IOException, MediaWikiApiErrorException { try (InputStream response = this.connection.sendRequest("POST", parameters)) { JsonNode root = this.mapper.readTree(response); this.connection.checkErrors(root); this.connection.logWarnings(root); if (root.has("item")) { return parseJsonResponse(root.path("item")); } else if (root.has("property")) { // TODO: not tested because of missing // permissions return parseJsonResponse(root.path("property")); } else if (root.has("entity")) { return parseJsonResponse(root.path("entity")); } else { throw new JsonMappingException("No entity document found in API response."); } } }