當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParseException類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:21,代碼來源:TenantLoginsResource.java

示例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;

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:JacksonPageModelParser.java

示例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));
}
 
開發者ID:XMBomb,項目名稱:InComb,代碼行數:18,代碼來源:ConfigTest.java

示例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;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:41,代碼來源:FirewallSubnetMaskResource.java

示例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 ('{"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:FunctionScoreQueryBuilderTests.java

示例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");
	}
}
 
開發者ID:shenan4321,項目名稱:BIMplatform,代碼行數:10,代碼來源:QueryObjectProvider.java

示例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());
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:30,代碼來源:LoggingFilter.java

示例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);
  }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:25,代碼來源:JSONRecordReader.java

示例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());
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:17,代碼來源:ResponseEntityTest.java

示例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"));
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:18,代碼來源:ParserUtilTest.java

示例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));
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:19,代碼來源:WelcomeMessageTest.java

示例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());
}
 
開發者ID:tdsis,項目名稱:lambda-forest,代碼行數:17,代碼來源:ResponseEntityTest.java

示例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());
}
 
開發者ID:leftso,項目名稱:demo-spring-boot-security-oauth2,代碼行數:26,代碼來源:GrantByImplicitProviderTest.java

示例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();
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:18,代碼來源:ExceptionMapperIT.java

示例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();
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:18,代碼來源:ExceptionMapperIT.java


注:本文中的com.fasterxml.jackson.core.JsonParseException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。