com.fasterxml.jackson.core.JsonLocation Java Examples

The following examples show how to use com.fasterxml.jackson.core.JsonLocation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicDeserializerFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ValueInstantiator _findStdValueInstantiator(DeserializationConfig config,
        BeanDescription beanDesc)
    throws JsonMappingException
{
    Class<?> raw = beanDesc.getBeanClass();
    if (raw == JsonLocation.class) {
        return new JsonLocationInstantiator();
    }
    // [databind#1868]: empty List/Set/Map
    if (Collection.class.isAssignableFrom(raw)) {
        if (Collections.EMPTY_SET.getClass() == raw) {
            return new ConstantValueInstantiator(Collections.EMPTY_SET);
        }
        if (Collections.EMPTY_LIST.getClass() == raw) {
            return new ConstantValueInstantiator(Collections.EMPTY_LIST);
        }
    } else if (Map.class.isAssignableFrom(raw)) {
        if (Collections.EMPTY_MAP.getClass() == raw) {
            return new ConstantValueInstantiator(Collections.EMPTY_MAP);
        }
    }
    return null;
}
 
Example #2
Source File: PartitionAwareServiceFactoryTest.java    From emodb with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: NodeDeserializer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: TagHelperTest.java    From herd with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: TitusExceptionMapper.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
private Response fromJsonProcessingException(JsonProcessingException e) {
    StringBuilder msgBuilder = new StringBuilder();
    if (e.getOriginalMessage() != null) {
        msgBuilder.append(e.getOriginalMessage());
    } else {
        msgBuilder.append("JSON processing error");
    }
    JsonLocation location = e.getLocation();
    if (location != null) {
        msgBuilder.append(" location: [line: ").append(location.getLineNr())
                .append(", column: ").append(location.getColumnNr()).append(']');
    }

    ErrorResponse errorResponse = ErrorResponse.newError(HttpServletResponse.SC_BAD_REQUEST, msgBuilder.toString())
            .clientRequest(httpServletRequest)
            .serverContext()
            .exceptionContext(e)
            .build();
    return Response.status(Status.BAD_REQUEST).entity(errorResponse).build();
}
 
Example #6
Source File: OpenRtbJsonExtComplexReader.java    From openrtb with Apache License 2.0 6 votes vote down vote up
@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());
    }
  }
}
 
Example #7
Source File: JsonReader.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public static JsonLocation expectArrayStart(JsonParser parser)
    throws IOException, JsonReadException
{
    if (parser.getCurrentToken() != JsonToken.START_ARRAY) {
        throw new JsonReadException("expecting the start of an array (\"[\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}
 
Example #8
Source File: JacksonStreamReaderImpl.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@link JacksonStreamReaderImpl} with the provided {@link JsonParser}.
 *
 * @param jp
 *            JsonParser from which to get tokens
 * @throws IOException
 *             Null JsonParser or error getting token
 */
public JacksonStreamReaderImpl(final JsonParser jp) throws IOException {
    if (jp == null) {
        throw new JacksonStreamReaderException("JsonParser cannot be null", JsonLocation.NA);
    }
    this.jp = jp;
    if (jp.getCurrentToken() == null) {
        jp.nextToken();
    }
}
 
Example #9
Source File: DbxClientV1.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
public CopyRef read(JsonParser parser)
    throws IOException, JsonReadException
{
    JsonLocation top = JsonReader.expectObjectStart(parser);

    String id = null;
    Date expires = null;

    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        parser.nextToken();

        try {
            if (fieldName.equals("copy_ref")) {
                id = JsonReader.StringReader.readField(parser, fieldName, id);
            }
            else if (fieldName.equals("expires")) {
                expires = JsonDateReader.Dropbox.readField(parser, fieldName, expires);
            }
            else {
                JsonReader.skipValue(parser);
            }
        }
        catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }

    JsonReader.expectObjectEnd(parser);

    if (id == null) throw new JsonReadException("missing field \"copy_ref\"", top);
    if (expires == null) throw new JsonReadException("missing field \"expires\"", top);

    return new CopyRef(id, expires);
}
 
Example #10
Source File: CustomProtobufParser.java    From caravan with Apache License 2.0 5 votes vote down vote up
/**
 * Overridden since we do not really have character-based locations,
 * but we do have byte offset to specify.
 */
@Override
public JsonLocation getCurrentLocation()
{
  final long offset = _currInputProcessed + _inputPtr;
  return new JsonLocation(_ioContext.getSourceReference(),
      offset, // bytes
      -1, -1, (int) offset); // char offset, line, column
}
 
Example #11
Source File: DbxAccountInfo.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public final Quota read(JsonParser parser)
    throws IOException, JsonReadException
{
    JsonLocation top = JsonReader.expectObjectStart(parser);

    long quota = -1;
    long normal = -1;
    long shared = -1;

    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        parser.nextToken();

        int fi = FM.get(fieldName);
        try {
            switch (fi) {
                case -1: JsonReader.skipValue(parser); break;
                case FM_quota: quota = JsonReader.readUnsignedLongField(parser, fieldName, quota); break;
                case FM_normal: normal = JsonReader.readUnsignedLongField(parser, fieldName, normal); break;
                case FM_shared: shared = JsonReader.readUnsignedLongField(parser, fieldName, shared); break;
                default:
                    throw new AssertionError("bad index: " + fi + ", field = \"" + fieldName + "\"");
            }
        }
        catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }

    JsonReader.expectObjectEnd(parser);

    if (quota < 0) throw new JsonReadException("missing field \"quota\"", top);
    if (normal < 0) throw new JsonReadException("missing field \"normal\"", top);
    if (shared < 0) throw new JsonReadException("missing field \"shared\"", top);

    return new Quota(quota, normal, shared);
}
 
Example #12
Source File: JsonReader.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public static JsonLocation expectArrayEnd(JsonParser parser)
    throws IOException, JsonReadException
{
    if (parser.getCurrentToken() != JsonToken.END_ARRAY) {
        throw new JsonReadException("expecting the end of an array (\"[\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}
 
Example #13
Source File: DataManagerImpl.java    From business with Mozilla Public License 2.0 5 votes vote down vote up
private void throwParsingError(JsonLocation jsonLocation, String message) {
    throw BusinessException.createNew(DataErrorCode.FAILED_TO_PARSE_DATA_STREAM)
            .put("parsingError", message)
            .put("line", jsonLocation.getLineNr())
            .put("col", jsonLocation.getColumnNr())
            .put("offset", jsonLocation.getCharOffset());
}
 
Example #14
Source File: BitlibJsonModule.java    From bitshares_wallet with MIT License 5 votes vote down vote up
@Override
public Address deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
   ObjectCodec oc = jp.getCodec();
   JsonNode node = oc.readTree(jp);
   Address address = Address.fromString(node.asText());
   if (address == null) {
      throw new JsonParseException("Failed to convert string '" + node.asText() + "' into an address",
            JsonLocation.NA);
   }
   return address;
}
 
Example #15
Source File: ParseError.java    From json-schema-validator-demo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static JsonNode build(final JsonProcessingException e,
    final boolean crlf)
{
    final JsonLocation location = e.getLocation();
    final ObjectNode ret = JsonNodeFactory.instance.objectNode();

    /*
     * Unfortunately, for some reason, Jackson botches the column number in
     * its JsonPosition -- I cannot figure out why exactly. However, it does
     * have a correct offset into the buffer.
     *
     * The problem is that if the input has CR/LF line terminators, its
     * offset will be "off" by the number of lines minus 1 with regards to
     * what JavaScript sees as positions in text areas. Make the necessary
     * adjustments so that the caret jumps at the correct position in this
     * case.
     */
    final int lineNr = location.getLineNr();
    int offset = (int) location.getCharOffset();
    if (crlf)
        offset = offset - lineNr + 1;
    ret.put(LINE, lineNr);
    ret.put(OFFSET, offset);

    // Finally, put the message
    ret.put(MESSAGE, e.getOriginalMessage());
    return ret;
}
 
Example #16
Source File: JsonReader.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public static JsonLocation expectObjectStart(JsonParser parser)
    throws IOException, JsonReadException
{
    if (parser.getCurrentToken() != JsonToken.START_OBJECT) {
        throw new JsonReadException("expecting the start of an object (\"{\")", parser.getTokenLocation());
    }
    JsonLocation loc = parser.getTokenLocation();
    nextToken(parser);
    return loc;
}
 
Example #17
Source File: IgnoredPropertyException.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Since 2.7
 */
@Deprecated
public IgnoredPropertyException(String msg, JsonLocation loc,
        Class<?> referringClass, String propName,
        Collection<Object> propertyIds)
{
    super(msg, loc, referringClass, propName, propertyIds);
}
 
Example #18
Source File: BaseJsonProcessor.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  JsonLocation location = parser.getCurrentLocation();
  return getClass().getSimpleName() + "[Line=" + location.getLineNr()
      + ", Column=" + (location.getColumnNr() + 1)
      + ", Field=" + getCurrentField()
      + "]";
}
 
Example #19
Source File: DbxUrlWithExpiration.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Override
public DbxUrlWithExpiration read(JsonParser parser)
    throws IOException, JsonReadException
{
    JsonLocation top = JsonReader.expectObjectStart(parser);

    String url = null;
    Date expires = null;

    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        parser.nextToken();

        try {
            if (fieldName.equals("url")) {
                url = JsonReader.StringReader.readField(parser, fieldName, url);
            }
            else if (fieldName.equals("expires")) {
                expires = JsonDateReader.Dropbox.readField(parser, fieldName, expires);
            }
            else {
                JsonReader.skipValue(parser);
            }
        }
        catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }

    JsonReader.expectObjectEnd(parser);

    if (url == null) throw new JsonReadException("missing field \"url\"", top);
    if (expires == null) throw new JsonReadException("missing field \"expires\"", top);

    return new DbxUrlWithExpiration(url, expires);
}
 
Example #20
Source File: BusinessObjectDefinitionHelperTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecuteFunctionForBusinessObjectDefinitionEntitiesJsonParseException()
{
    // Create a list of business object definition entities.
    final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Collections.unmodifiableList(Arrays.asList(
        businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION,
            businessObjectDefinitionServiceTestHelper.getNewAttributes()), businessObjectDefinitionDaoTestHelper
            .createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2,
                businessObjectDefinitionServiceTestHelper.getNewAttributes2())));

    businessObjectDefinitionEntities.forEach(entity ->
    {
        entity.setDescriptiveBusinessObjectFormat(new BusinessObjectFormatEntity());
        entity.getDescriptiveBusinessObjectFormat().setSchemaColumns(new ArrayList<>());

        entity.setSubjectMatterExperts(new ArrayList<>());
    });

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

    // Execute a function for all business object definition entities.
    businessObjectDefinitionHelper
        .executeFunctionForBusinessObjectDefinitionEntities(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE, businessObjectDefinitionEntities,
            (indexName, documentType, id, json) ->
            {
            });

    // Verify the external calls.
    verify(jsonHelper, times(businessObjectDefinitionEntities.size())).objectToJson(any());
    verifyNoMoreInteractions(alternateKeyHelper, jsonHelper);
}
 
Example #21
Source File: TagServiceIndexTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testIndexSpotCheckPercentageValidationTagsObjectMappingException() throws Exception
{
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);

    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION),
        tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));

    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class)).thenReturn(0.2);
    when(tagDao.getPercentageOfAllTags(0.2)).thenReturn(rootTagEntities);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(jsonHelper.objectToJson(any()))
        .thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));

    // Call the method under test
    boolean isSpotCheckPercentageValid = tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_TYPE_TAG);

    assertThat("Tag service index spot check random validation is true when it should have been false.", isSpotCheckPercentageValid, is(false));

    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class);
    verify(tagDao).getPercentageOfAllTags(0.2);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verifyNoMoreInteractions(tagDao, configurationHelper, jsonHelper);
}
 
Example #22
Source File: TagServiceIndexTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testIndexSpotCheckMostRecentValidationTagsObjectMappingException() throws Exception
{
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);

    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION),
        tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));

    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class)).thenReturn(10);
    when(tagDao.getMostRecentTags(10)).thenReturn(rootTagEntities);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
    when(jsonHelper.objectToJson(any()))
        .thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
    when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(false);

    // Call the method under test
    boolean isSpotCheckMostRecentValid = tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_TYPE_TAG);

    assertThat("Tag service index spot check most recent validation is true when it should have been false.", isSpotCheckMostRecentValid, is(false));

    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
    verify(tagDao).getMostRecentTags(10);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
    verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
    verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper, jsonHelper, tagHelper);
}
 
Example #23
Source File: BusinessObjectDefinitionServiceIndexTest.java    From herd with Apache License 2.0 5 votes vote down vote up
@Test
public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjectMappingException()
{
    List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>();
    businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper
        .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION,
            businessObjectDefinitionServiceTestHelper.getNewAttributes()));
    businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper
        .createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2,
            businessObjectDefinitionServiceTestHelper.getNewAttributes()));

    // Mock the call to external methods
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class)).thenReturn(100);
    when(businessObjectDefinitionDao.getMostRecentBusinessObjectDefinitions(100)).thenReturn(businessObjectDefinitionEntityList);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_DOCUMENT_TYPE);
    when(jsonHelper.objectToJson(any()))
        .thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
    when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(false);

    // Call the method under test
    boolean isSpotCheckPercentageValid = businessObjectDefinitionService.indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);

    assertThat("Business object definition service index spot check most recent validation is true when it should have been false.",
        isSpotCheckPercentageValid, is(false));

    // Verify the calls to external methods
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
    verify(businessObjectDefinitionDao).getMostRecentBusinessObjectDefinitions(100);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(businessObjectDefinitionHelper, times(2)).safeObjectMapperWriteValueAsString(any(BusinessObjectDefinitionEntity.class));
    verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
    verifyNoMoreInteractionsHelper();
}
 
Example #24
Source File: UserDeserializer.java    From osiam with MIT License 5 votes vote down vote up
@Override
public User deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode rootNode = jp.readValueAsTree();

    User user = MAPPER.readValue(rootNode.traverse(), User.class);
    if (user.getSchemas() == null) {
        throw new JsonMappingException(jp, "Required field 'schemas' is missing");
    }
    if (user.getSchemas().size() == 1) {
        return user;
    }

    User.Builder builder = new User.Builder(user);

    for (String urn : user.getSchemas()) {
        if (urn.equals(schema)) {
            continue;
        }

        JsonNode extensionNode = rootNode.get(urn);
        if (extensionNode == null) {
            throw new JsonParseException(jp, "Registered extension not present: " + urn, JsonLocation.NA);
        }

        builder.addExtension(deserializeExtension(jp, extensionNode, urn));

    }
    return builder.build();
}
 
Example #25
Source File: JsonParseExceptionMapper.java    From heroic with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(JsonParseException e) {
    final JsonLocation l = e.getLocation();

    return Response
        .status(Response.Status.BAD_REQUEST)
        .entity(new JsonParseErrorMessage(e.getOriginalMessage(), Response.Status.BAD_REQUEST,
            l.getLineNr(), l.getColumnNr()))
        .type(MediaType.APPLICATION_JSON)
        .build();
}
 
Example #26
Source File: DbxEntry.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public final DbxEntry./*@Nullable*/File read(JsonParser parser)
    throws IOException, JsonReadException
{
    JsonLocation top = parser.getCurrentLocation();
    WithChildrenC<?> wc = DbxEntry._read(parser, null, true);
    if (wc == null) return null;
    DbxEntry e = wc.entry;
    if (!(e instanceof DbxEntry.File)) {
        throw new JsonReadException("Expecting a file entry, got a folder entry", top);
    }
    return (DbxEntry.File) e;
}
 
Example #27
Source File: DbxAccountInfo.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public final NameDetails read(JsonParser parser)
        throws IOException, JsonReadException
{
    JsonLocation top = JsonReader.expectObjectStart(parser);

    String familiarName = null;
    String givenName = null;
    String surname = null;

    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        parser.nextToken();

        int fi = FM.get(fieldName);
        try {
            switch (fi) {
                case -1: JsonReader.skipValue(parser); break;
                case FM_familiar_name: familiarName = JsonReader.StringReader.readField(parser, fieldName, familiarName); break;
                case FM_given_name: givenName = JsonReader.StringReader.readField(parser, fieldName, givenName); break;
                case FM_surname: surname = JsonReader.StringReader.readField(parser, fieldName, surname); break;
                default:
                    throw new AssertionError("bad index: " + fi + ", field = \"" + fieldName + "\"");
            }
        }
        catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }

    JsonReader.expectObjectEnd(parser);

    if (familiarName == null) throw new JsonReadException("missing field \"familiarName\"", top);
    if (surname == null) throw new JsonReadException("missing field \"surname\"", top);
    if (givenName == null) throw new JsonReadException("missing field \"givenName\"", top);

    return new NameDetails(familiarName, givenName, surname);
}
 
Example #28
Source File: DbxEntry.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public final DbxEntry.File read(JsonParser parser)
    throws IOException, JsonReadException
{
    JsonLocation top = parser.getCurrentLocation();
    DbxEntry e = DbxEntry.read(parser, null).entry;
    if (!(e instanceof DbxEntry.File)) {
        throw new JsonReadException("Expecting a file entry, got a folder entry", top);
    }
    return (DbxEntry.File) e;
}
 
Example #29
Source File: NodeDeserializer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
protected ValueNode deserializeValueNode(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);

    Object v = context.readValue(p, Object.class);

    ValueNode node = model.valueNode(parent, ptr, v);
    node.setStartLocation(createLocation(startLocation));
    node.setEndLocation(createLocation(p.getCurrentLocation()));

    return node;
}
 
Example #30
Source File: DbxOAuth1Upgrader.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
public String read(JsonParser parser) throws IOException, JsonReadException
{
    JsonLocation top = JsonReader.expectObjectStart(parser);

    String accessToken = null;
    String tokenType = null;

    while (parser.getCurrentToken() == JsonToken.FIELD_NAME) {
        String fieldName = parser.getCurrentName();
        JsonReader.nextToken(parser);

        try {
            if (fieldName.equals("token_type")) {
                tokenType = DbxAuthFinish.BearerTokenTypeReader.readField(parser, fieldName, tokenType);
            }
            else if (fieldName.equals("access_token")) {
                accessToken = DbxAuthFinish.AccessTokenReader.readField(parser, fieldName, accessToken);
            }
            else {
                // Unknown field.  Skip over it.
                JsonReader.skipValue(parser);
            }
        }
        catch (JsonReadException ex) {
            throw ex.addFieldContext(fieldName);
        }
    }

    JsonReader.expectObjectEnd(parser);

    if (tokenType == null) throw new JsonReadException("missing field \"token_type\"", top);
    if (accessToken == null) throw new JsonReadException("missing field \"access_token\"", top);

    return accessToken;
}