当前位置: 首页>>代码示例>>Java>>正文


Java JsonLocation类代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.JsonLocation的典型用法代码示例。如果您正苦于以下问题:Java JsonLocation类的具体用法?Java JsonLocation怎么用?Java JsonLocation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonLocation类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testJsonParseException

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Test
public void testJsonParseException(@Mocked Response response, @Mocked ResponseBuilder builder) {
    exMapper.toResponse(new JsonParseException("TestException", JsonLocation.NA));
    
    new Verifications() {{
        ResponseBuilder rb;
        Status s;
        String json;
        
        rb = Response.status(s = withCapture()); times = 1;
        rb.entity(json = withCapture()); times = 1;
        
        Assert.assertEquals(Response.Status.BAD_REQUEST, s);
        Assert.assertTrue("Stringified json should include status 400: [" + json + "]", 
                json.contains("\"status\":400"));
        Assert.assertTrue("Stringified json should include message containing exception's message: [" + json + "]", 
                json.contains("\"message\":\"TestException\\n at [Source: N/A; line: -1, column: -1]\""));
        Assert.assertFalse("Stringified json should not include info: [" + json + "]", 
                json.contains("more_info"));
    }};
}
 
开发者ID:gameontext,项目名称:gameon-player,代码行数:22,代码来源:ErrorResponseMapperTest.java

示例2: testJsonParseException

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Test
public void testJsonParseException(@Mocked Response response, @Mocked ResponseBuilder builder) {
    exMapper.toResponse(new JsonParseException("TestException", JsonLocation.NA));

    new Verifications() {{
        ResponseBuilder rb;
        Status s;
        String json;

        rb = Response.status(s = withCapture()); times = 1;
        rb.entity(json = withCapture()); times = 1;

        Assert.assertEquals(Response.Status.BAD_REQUEST, s);
        Assert.assertTrue("Stringified json should include status 400: [" + json + "]",
                json.contains("\"status\":400"));
        Assert.assertTrue("Stringified json should include message containing exception's message: [" + json + "]",
                json.contains("\"message\":\"TestException\\n at [Source: N/A; line: -1, column: -1]\""));
        Assert.assertFalse("Stringified json should not include info: [" + json + "]",
                json.contains("more_info"));
    }};
}
 
开发者ID:gameontext,项目名称:gameon-map,代码行数:22,代码来源:ErrorResponseMapperTest.java

示例3: testDelegateDeclaredExceptionPropagation

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Test
public void testDelegateDeclaredExceptionPropagation() throws Exception {
    doThrow(new JsonParseException("Simulated declared exception", JsonLocation.NA)).when(_delegate).doIt();
    TestInterface service = _serviceFactory.create(_remoteEndPoint);

    try {
        service.doIt();
        fail("JsonParseException not thrown");
    } catch (JsonParseException e) {
        assertEquals(e.getOriginalMessage(), "Simulated declared exception");
    }

    assertEquals(_metricRegistry.getMeters().get("bv.emodb.web.partition-forwarding.TestInterface.errors").getCount(), 0);
    
    verify(_delegateServiceFactory).create(_remoteEndPoint);
    verify(_delegate).doIt();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:18,代码来源:PartitionAwareServiceFactoryTest.java

示例4: JsonState

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
JsonState(
    final JsonToken token,
    final String text,
    final String name,
    final int intValue,
    final String stringValue,
    final long longValue,
    final double doubleValue,
    final boolean booleanValue,
    final JsonLocation location) {

  this.token = token;
  this.text = text;
  this.name = name;
  this.intValue = intValue;
  this.stringValue = stringValue;
  this.longValue = longValue;
  this.doubleValue = doubleValue;
  this.booleanValue = booleanValue;
  this.location = location;
}
 
开发者ID:SumoLogic,项目名称:epigraph,代码行数:22,代码来源:AbstractJsonFormatReader.java

示例5: testSafeObjectMapperWriteValueAsStringJsonParseException

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Test
public void testSafeObjectMapperWriteValueAsStringJsonParseException()
{
    // Create a tag entity.
    final TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION);

    // Mock the external calls.
    when(jsonHelper.objectToJson(any()))
        .thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));

    // Call the method being tested.
    String result = tagHelper.safeObjectMapperWriteValueAsString(tagEntity);

    // Verify the external calls.
    verify(jsonHelper).objectToJson(any());
    verifyNoMoreInteractions(alternateKeyHelper, jsonHelper);

    // Validate the returned object.
    assertEquals("", result);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:21,代码来源:TagHelperTest.java

示例6: testHandle

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Test
public void testHandle() throws Exception {
    // Given
    JsonLocation loc = new JsonLocation(null, 1L, 1, 1, 1);
    Class<?> clz = UnrecognizedPropertyException.class;
    Collection<Object> fields = Arrays.asList("field1", "field2");
    String propName = "propName";
    String message = "message";
    UnrecognizedPropertyException e = new UnrecognizedPropertyException(message, loc, clz, propName, fields);

    MessageResource expected = new UnrecognizedPropertyMessageResource(MessageType.ERROR, "Unrecognized Property sent", propName, fields.stream().map(field -> field.toString()).collect(Collectors.toList()));

    // When
    MessageResource actual = unit.handle(e);

    // Then
    assertEquals(expected, actual);
}
 
开发者ID:ifnul,项目名称:ums-backend,代码行数:19,代码来源:UnrecognizedPropertyExceptionHandlerTest.java

示例7: deserialize

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Override
public AbstractNode deserialize(JsonParser p, DeserializationContext context)
        throws IOException, JsonProcessingException {

    JsonLocation startLocation = p.getTokenLocation();
    if (p.getCurrentToken() == JsonToken.FIELD_NAME) {
        p.nextToken();
    }

    switch (p.getCurrentToken()) {
    case START_OBJECT:
        return deserializeObjectNode(p, context, startLocation);
    case START_ARRAY:
        return deserializeArrayNode(p, context, startLocation);
    default:
        return deserializeValueNode(p, context, startLocation);
    }
}
 
开发者ID:RepreZen,项目名称:KaiZen-OpenAPI-Editor,代码行数:19,代码来源:NodeDeserializer.java

示例8: deserializeObjectNode

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
protected ObjectNode deserializeObjectNode(JsonParser p, DeserializationContext context, JsonLocation startLocation)
        throws IllegalArgumentException, IOException {

    final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
    final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
    final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);

    final ObjectNode node = model.objectNode(parent, ptr);
    node.setStartLocation(createLocation(startLocation));

    while (p.nextToken() != JsonToken.END_OBJECT) {
        String name = p.getCurrentName();

        JsonPointer pp = JsonPointer.compile(ptr.toString() + "/" + name.replaceAll("/", "~1"));
        context.setAttribute(ATTRIBUTE_PARENT, node);
        context.setAttribute(ATTRIBUTE_POINTER, pp);

        AbstractNode v = deserialize(p, context);
        v.setProperty(name);
        node.put(name, v);
    }

    node.setEndLocation(createLocation(p.getCurrentLocation()));
    return node;
}
 
开发者ID:RepreZen,项目名称:KaiZen-OpenAPI-Editor,代码行数:26,代码来源:NodeDeserializer.java

示例9: deserializeArrayNode

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
protected ArrayNode deserializeArrayNode(JsonParser p, DeserializationContext context, JsonLocation startLocation)
        throws IOException {
    final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
    final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
    final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);

    ArrayNode node = model.arrayNode(parent, ptr);

    int i = 0;
    while (p.nextToken() != JsonToken.END_ARRAY) {
        JsonPointer pp = JsonPointer.compile(ptr.toString() + "/" + i);

        context.setAttribute(ATTRIBUTE_PARENT, node);
        context.setAttribute(ATTRIBUTE_POINTER, pp);

        AbstractNode v = deserialize(p, context);

        node.add(v);
        i++;
    }

    node.setStartLocation(createLocation(startLocation));
    node.setEndLocation(createLocation(p.getCurrentLocation()));
    return node;
}
 
开发者ID:RepreZen,项目名称:KaiZen-OpenAPI-Editor,代码行数:26,代码来源:NodeDeserializer.java

示例10: readSingle

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void readSingle(EB msg, JsonParser par, XB ext) throws IOException {
  if (isJsonObject) {
    startObject(par);
  }
  boolean extRead = false;
  JsonToken tokLast = par.getCurrentToken();
  JsonLocation locLast = par.getCurrentLocation();
  while (endObject(par) && (isJsonObject || filter(par))) {
    read(ext, par);
    if (par.getCurrentToken() != tokLast || !par.getCurrentLocation().equals(locLast)) {
      extRead = true;
      par.nextToken();
      tokLast = par.getCurrentToken();
      locLast = par.getCurrentLocation();
    } else {
      break;
    }
  }
  if (extRead) {
    msg.setExtension(key, ext.build());
  }
  if (isJsonObject) {
    par.nextToken();
  }
}
 
开发者ID:google,项目名称:openrtb,代码行数:27,代码来源:OpenRtbJsonExtComplexReader.java

示例11: readRepeated

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void readRepeated(EB msg, JsonParser par) throws IOException {
  par.nextToken();
  JsonToken tokLast = par.getCurrentToken();
  JsonLocation locLast = par.getCurrentLocation();
  for (startArray(par); endArray(par); par.nextToken()) {
    boolean objRead = false;
    XB ext = (XB) key.getMessageDefaultInstance().toBuilder();
    for (startObject(par); endObject(par); par.nextToken()) {
      read(ext, par);
      JsonToken tokNew = par.getCurrentToken();
      JsonLocation locNew = par.getCurrentLocation();
      if (tokNew != tokLast || !locNew.equals(locLast)) {
        objRead = true;
      }
      tokLast = tokNew;
      locLast = locNew;
    }
    if (objRead) {
      msg.addExtension(key, ext.build());
    }
  }
}
 
开发者ID:google,项目名称:openrtb,代码行数:24,代码来源:OpenRtbJsonExtComplexReader.java

示例12: getLocationString

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
private String getLocationString() {
  JsonLocation l = parser.getCurrentLocation();
  List<String> parts = new ArrayList<>(4);
  parts.add("line: " + l.getLineNr());
  parts.add("column: " + l.getColumnNr());
  if (l.getByteOffset() >= 0) {
    parts.add("byte offset: " + l.getByteOffset());
  }
  return parts.toString();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:JsonParserReader.java

示例13: getTokenLocation

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Override
public XContentLocation getTokenLocation() {
    JsonLocation loc = parser.getTokenLocation();
    if (loc == null) {
        return null;
    }
    return new XContentLocation(loc.getLineNr(), loc.getColumnNr());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:JsonXContentParser.java

示例14: deserialize

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
@Override
    public JSONOptions deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
        JsonProcessingException {
      JsonLocation l = jp.getTokenLocation();
//      logger.debug("Reading tree.");
      TreeNode n = jp.readValueAsTree();
//      logger.debug("Tree {}", n);
      if (n instanceof JsonNode) {
        return new JSONOptions( (JsonNode) n, l);
      } else {
        throw new IllegalArgumentException(String.format("Received something other than a JsonNode %s", n));
      }
    }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:14,代码来源:JSONOptions.java

示例15: getJacksonProcessingExceptionMessage

import com.fasterxml.jackson.core.JsonLocation; //导入依赖的package包/类
private static String getJacksonProcessingExceptionMessage(JsonProcessingException ex) {
    JsonLocation loc = ex.getLocation();
    if (loc != null) {
        return String.format("Failed to decode JSON at line: %s, column: %s", loc.getLineNr(), loc.getColumnNr());
    }
    return "Failed to decode JSON";
}
 
开发者ID:valuelogic,项目名称:vertx-web-problem,代码行数:8,代码来源:ProblemFactory.java


注:本文中的com.fasterxml.jackson.core.JsonLocation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。