本文整理汇总了Java中com.fasterxml.jackson.core.JsonParseException类的典型用法代码示例。如果您正苦于以下问题:Java JsonParseException类的具体用法?Java JsonParseException怎么用?Java JsonParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonParseException类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
/**
* Validate logins yml.
* @param loginsYml logins yml
* @return true if valid
*/
@PostMapping(value = "/logins/validate", consumes = {TEXT_PLAIN_VALUE})
@ApiOperation(value = "Validate uaa login properties format", response = UaaValidationVM.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Uaa validation result", response = UaaValidationVM.class),
@ApiResponse(code = 500, message = "Internal server error")})
@SneakyThrows
@Timed
public UaaValidationVM validate(@RequestBody String loginsYml) {
try {
mapper.readValue(loginsYml, TenantLogins.class);
return UaaValidationVM.builder().isValid(true).build();
} catch (JsonParseException | JsonMappingException e) {
return UaaValidationVM.builder().isValid(false).errorMessage(e.getLocalizedMessage()).build();
}
}
示例2: parseRegions
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
/**
* @param parser
* @param layoutId
* @throws JsonParseException
* @throws IOException
*/
private List<RegionInstance> parseRegions(JsonParser parser, String segment) throws JsonParseException, IOException {
JsonToken current = parser.nextToken();
assertExpectedJsonToken(current, JsonToken.START_ARRAY, parser.getCurrentLocation());
List<RegionInstance> instances = new ArrayList<RegionInstance>();
while ((current = parser.nextToken()) != JsonToken.END_ARRAY) {
assertExpectedJsonToken(current, JsonToken.START_OBJECT, parser.getCurrentLocation());
String regionId = getNextTextValue("cid", parser); // get regionId
RegionEnum region = RegionEnum.valueOf(regionId);
current = parser.nextToken(); // move to field: widgtes
assertExpectedFiled(parser.getCurrentName(), "widgets", parser.getCurrentLocation());
RegionInstance instance = new RegionInstance();
instance.setWidgtes(parseWidgets(parser, region));
instances.add(instance);
assertExpectedJsonToken((current = parser.nextToken()), JsonToken.END_OBJECT, parser.getCurrentLocation());
}
return instances;
}
示例3: testArray
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@Test
public void testArray() throws JsonParseException, JsonMappingException, IOException {
assertTrue(config.getProperty("phoneNumbers", List.class) instanceof List);
final List<Map<String, String>> testList = new ArrayList<>();
Map<String, String> testMapEntry = new HashMap<>();
testMapEntry.put("type", "home");
testMapEntry.put("number", "212 555-1234");
testList.add(testMapEntry);
testMapEntry = new HashMap<>();
testMapEntry.put("type", "office");
testMapEntry.put("number", "646 555-4567");
testList.add(testMapEntry);
assertEquals(testList, config.getProperty("phoneNumbers", List.class));
assertEquals(new ArrayList<>(), config.getProperty("children", List.class));
}
示例4: jsonExtractSubnetMask
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
/**
* Extracts subnet mask from a JSON string
* @param fmJson The JSON formatted string
* @return The subnet mask
* @throws IOException If there was an error parsing the JSON
*/
public static String jsonExtractSubnetMask(String fmJson) throws IOException {
String subnet_mask = "";
MappingJsonFactory f = new MappingJsonFactory();
JsonParser jp;
try {
jp = f.createParser(fmJson);
} catch (JsonParseException e) {
throw new IOException(e);
}
jp.nextToken();
if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected START_OBJECT");
}
while (jp.nextToken() != JsonToken.END_OBJECT) {
if (jp.getCurrentToken() != JsonToken.FIELD_NAME) {
throw new IOException("Expected FIELD_NAME");
}
String n = jp.getCurrentName();
jp.nextToken();
if (jp.getText().equals(""))
continue;
if (n == "subnet-mask") {
subnet_mask = jp.getText();
break;
}
}
return subnet_mask;
}
示例5: testMalformedThrowsException
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
public void testMalformedThrowsException() throws IOException {
String json = "{\n" +
" \"function_score\":{\n" +
" \"query\":{\n" +
" \"term\":{\n" +
" \"name.last\":\"banon\"\n" +
" }\n" +
" },\n" +
" \"functions\": [\n" +
" {\n" +
" {\n" +
" }\n" +
" ]\n" +
" }\n" +
"}";
JsonParseException e = expectThrows(JsonParseException.class, () -> parseQuery(json));
assertThat(e.getMessage(), containsString("Unexpected character ('{"));
}
示例6: fromJsonNode
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
public static QueryObjectProvider fromJsonNode(CatalogService catalogService, VirtualObjectService virtualObjectService, PlatformServer server, JsonNode fullQuery, Integer rid, PackageMetaData packageMetaData) throws JsonParseException, JsonMappingException, IOException, QueryException {
if (fullQuery instanceof ObjectNode) {
JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(packageMetaData);
Query query = converter.parseJson("query", (ObjectNode) fullQuery);
return new QueryObjectProvider(catalogService, virtualObjectService, server, query, rid, packageMetaData);
} else {
throw new QueryException("Query root must be of type object");
}
}
示例7: logResponse
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
/**
* Log response.
*
* @param response the response
* @param the
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
private void logResponse(final ResponseWrapper response) throws JsonParseException,
JsonMappingException, IOException {
StringBuilder msg = new StringBuilder();
msg.append(RESPONSE_PREFIX);
msg.append("\nid: '").append((response.getId())).append("' ");
try {
ObjectMapper mapper = new ObjectMapper();
Object json =
mapper.readValue(
new String(response.getData(), response.getCharacterEncoding()),
Object.class);
msg.append("\nResponse: \n").append(
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json));
} catch (UnsupportedEncodingException e) {
_log.error("[logResponse] Exception: " + e.getMessage(), e);
}
_log.info("[logResponse] Response: " + msg.toString());
}
示例8: handleAndRaise
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
protected void handleAndRaise(String suffix, Exception e) throws UserException {
String message = e.getMessage();
int columnNr = -1;
if (e instanceof JsonParseException) {
final JsonParseException ex = (JsonParseException) e;
message = ex.getOriginalMessage();
columnNr = ex.getLocation().getColumnNr();
}
UserException.Builder exceptionBuilder = UserException.dataReadError(e)
.message("%s - %s", suffix, message);
if (columnNr > 0) {
exceptionBuilder.pushContext("Column ", columnNr);
}
if (hadoopPath != null) {
exceptionBuilder.pushContext("Record ", currentRecordNumberInFile())
.pushContext("File ", hadoopPath.toUri().getPath());
}
throw exceptionBuilder.build(logger);
}
示例9: shouldOverwriteDefaultHttpStatusCode
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@Test
public void shouldOverwriteDefaultHttpStatusCode() throws JsonParseException, JsonMappingException, IOException {
UserRequestTest request = new UserRequestTest("user name", "user address");
ResponseEntity response = ResponseEntity.of(request, HttpStatus.SC_ACCEPTED);
Assert.assertEquals(HttpStatus.SC_ACCEPTED, response.getStatusCode());
Assert.assertNotNull(response.getBody());
//should be able to deserialize
UserRequestTest deserialized = new ObjectMapper().readValue(response.getBody(), UserRequestTest.class);
Assert.assertNotNull(request);
Assert.assertEquals(request.getName(), deserialized.getName());
Assert.assertEquals(request.getAddress(), deserialized.getAddress());
Assert.assertNull(response.getHeaders());
}
示例10: testReadArray
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testReadArray() throws JsonParseException, IOException {
ObjectMapper om = new ObjectMapper();
JsonParser jp = om.getFactory().createParser("\"test\"");
jp.nextToken();
assertThat(ParserUtil.readArray(jp)).isNull();
jp = om.getFactory().createParser("[1,2,3]");
jp.nextToken();
assertThat(ParserUtil.readArray(jp)).containsExactly(1, 2, 3);
jp = om.getFactory().createParser("[[\"k\",\"l\",\"m\"],[\"a\",\"b\",\"c\"]]");
jp.nextToken();
assertThat(ParserUtil.readArray(jp)).containsExactly(Arrays.asList("k", "l", "m"),
Arrays.asList("a", "b", "c"));
}
示例11: serializeTest
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked" })
@Test
public void serializeTest()
throws JsonParseException, JsonMappingException, IOException {
List<WampRole> roles = createRoles();
WelcomeMessage welcomeMessage = new WelcomeMessage(9129137332L, roles, "realm");
assertThat(welcomeMessage.getCode()).isEqualTo(2);
assertThat(welcomeMessage.getSessionId()).isEqualTo(9129137332L);
assertThat(welcomeMessage.getRoles()).isEqualTo(roles);
String json = serializeToJson(welcomeMessage);
String expected = "[2,9129137332,{\"roles\":{\"dealer\":{\"features\":{\"caller_identification\":true}},\"broker\":{\"features\":{\"subscriber_blackwhite_listing\":true,\"publisher_exclusion\":true,\"publisher_identification\":true,\"pattern_based_subscription\":true}}},\"realm\":\"realm\"}]";
ObjectMapper om = new ObjectMapper();
assertThat(om.readValue(json, List.class))
.isEqualTo(om.readValue(expected, List.class));
}
示例12: shouldSerializeSimpleResponseBody
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@Test
public void shouldSerializeSimpleResponseBody() throws JsonParseException, JsonMappingException, IOException {
UserRequestTest request = new UserRequestTest("user name", "user address");
ResponseEntity response = ResponseEntity.of(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode());
Assert.assertNotNull(response.getBody());
//should be able to deserialize
UserRequestTest deserialized = new ObjectMapper().readValue(response.getBody(), UserRequestTest.class);
Assert.assertNotNull(request);
Assert.assertEquals(request.getName(), deserialized.getName());
Assert.assertEquals(request.getAddress(), deserialized.getAddress());
Assert.assertNull(response.getHeaders());
}
示例13: getJwtTokenByImplicitGrant
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
@Test
public void getJwtTokenByImplicitGrant() throws JsonParseException, JsonMappingException, IOException {
String redirectUrl = "http://localhost:"+port+"/resources/user";
ResponseEntity<String> response = new TestRestTemplate("user","password").postForEntity("http://localhost:" + port
+ "oauth/authorize?response_type=token&client_id=normal-app&redirect_uri={redirectUrl}", null, String.class,redirectUrl);
assertEquals(HttpStatus.OK, response.getStatusCode());
List<String> setCookie = response.getHeaders().get("Set-Cookie");
String jSessionIdCookie = setCookie.get(0);
String cookieValue = jSessionIdCookie.split(";")[0];
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", cookieValue);
response = new TestRestTemplate("user","password").postForEntity("http://localhost:" + port
+ "oauth/authorize?response_type=token&client_id=normal-app&redirect_uri={redirectUrl}&user_oauth_approval=true&authorize=Authorize",
new HttpEntity<>(headers), String.class, redirectUrl);
assertEquals(HttpStatus.FOUND, response.getStatusCode());
assertNull(response.getBody());
String location = response.getHeaders().get("Location").get(0);
//FIXME: Is this a bug with redirect URL?
location = location.replace("#", "?");
response = new TestRestTemplate().getForEntity(location, String.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
}
示例14: assertForbidden
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
private void assertForbidden(final String path) throws IOException, ClientProtocolException, JsonParseException, JsonMappingException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + path);
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("security", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertNull(result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
示例15: assertUnavailable
import com.fasterxml.jackson.core.JsonParseException; //导入依赖的package包/类
private void assertUnavailable(final String path) throws IOException, ClientProtocolException, JsonParseException, JsonMappingException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + path);
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertNull(result.get("message"));
Assert.assertEquals("database-down", result.get("code"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}