com.fasterxml.jackson.core.ObjectCodec Java Examples

The following examples show how to use com.fasterxml.jackson.core.ObjectCodec. 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: JiraCommentDeserialiser.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public JiraComment deserialize(JsonParser parser,
        DeserializationContext context) throws IOException,
        JsonProcessingException {
    
    
    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);

    JiraComment comment = new JiraComment();

    comment.setCommentId(getText(node, "id"));
    comment.setCreationTime(getDate(node, context, "created"));
    comment.setCreator(getText(node, "author", "name"));
    comment.setText(getText(node, "body"));
    comment.setUpdateAuthor(getText(node, "updateAuthor", "name"));
    comment.setUpdateDate(getDate(node, context, "updated"));
    comment.setUrl(getText(node, "self"));

    return comment;

}
 
Example #2
Source File: ExposedPorts.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ExposedPorts deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    List<ExposedPort> exposedPorts = new ArrayList<>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext(); ) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            exposedPorts.add(ExposedPort.parse(field.getKey()));
        }
    }
    return new ExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
}
 
Example #3
Source File: CoinbaseAddresses.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
@Override
public CoinbaseAddresses deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  final ObjectCodec oc = jp.getCodec();
  final JsonNode node = oc.readTree(jp);
  final JsonNode addressesArrayNode = node.path("addresses");

  final List<CoinbaseAddress> addresses = new ArrayList<>();
  for (JsonNode addressNode : addressesArrayNode) {
    addresses.add(getAddressFromNode(addressNode));
  }

  final int totalCount = node.path("total_count").asInt();
  final int numPages = node.path("num_pages").asInt();
  final int currentPage = node.path("current_page").asInt();

  return new CoinbaseAddresses(addresses, totalCount, numPages, currentPage);
}
 
Example #4
Source File: JSonBindingUtils.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Override
public TargetWrapperDescriptor deserialize( JsonParser parser, DeserializationContext context ) throws IOException {

	ObjectCodec oc = parser.getCodec();
	JsonNode node = oc.readTree( parser );
	TargetWrapperDescriptor twd = new TargetWrapperDescriptor();

	JsonNode n;
	if(( n = node.get( DESC )) != null )
		twd.setDescription( n.textValue());

	if(( n = node.get( TARGET_HANDLER )) != null )
		twd.setHandler( n.textValue());

	if(( n = node.get( ID )) != null )
		twd.setId( n.textValue());

	if(( n = node.get( NAME )) != null )
		twd.setName( n.textValue());

	return twd;
}
 
Example #5
Source File: CoinbasePrice.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
@Override
public CoinbasePrice deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  final ObjectCodec oc = jp.getCodec();
  final JsonNode node = oc.readTree(jp);
  final CoinbaseMoney subTotal =
      CoinbaseMoneyDeserializer.getCoinbaseMoneyFromNode(node.path("subtotal"));
  final JsonNode feesNode = node.path("fees");
  final CoinbaseMoney coinbaseFee =
      CoinbaseMoneyDeserializer.getCoinbaseMoneyFromNode(feesNode.path(0).path("coinbase"));
  final CoinbaseMoney bankFee =
      CoinbaseMoneyDeserializer.getCoinbaseMoneyFromNode(feesNode.path(1).path("bank"));
  final CoinbaseMoney total =
      CoinbaseMoneyDeserializer.getCoinbaseMoneyFromNode(node.path("total"));
  return new CoinbasePrice(coinbaseFee, bankFee, total, subTotal);
}
 
Example #6
Source File: AbstractJobParametersDeserializer.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public T deserialize( JsonParser p, DeserializationContext ctxt ) throws IOException
{
    final ObjectCodec oc = p.getCodec();
    final JsonNode jsonNode;

    if ( oc instanceof XmlMapper )
    {
        jsonNode = createJsonNode( p, ctxt );
        return objectMapper.treeToValue( jsonNode, overrideClass );
    }
    else
    {
        jsonNode = oc.readTree( p );
        // original object mapper must be used since it may have different serialization settings
        return oc.treeToValue( jsonNode, overrideClass );
    }
}
 
Example #7
Source File: PublicKeyHashMapDeserializer.java    From steem-java-api-wrapper with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<PublicKey, Integer> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    HashMap<PublicKey, Integer> result = new HashMap<>();

    ObjectCodec codec = jsonParser.getCodec();
    TreeNode rootNode = codec.readTree(jsonParser);

    if (rootNode.isArray()) {
        for (JsonNode node : (ArrayNode) rootNode) {
            PublicKey publicKey = new PublicKey((node.get(0)).asText());
            result.put(publicKey, (node.get(0)).asInt());
        }

        return result;
    }

    throw new IllegalArgumentException("JSON Node is not an array.");
}
 
Example #8
Source File: LogicalFilter4.java    From jolt with Apache License 2.0 6 votes vote down vote up
@Override
public LogicalFilter4 deserialize( JsonParser jp, DeserializationContext ctxt ) throws IOException {

    ObjectCodec objectCodec = jp.getCodec();
    ObjectNode root = jp.readValueAsTree();

    // We assume it is a LogicalFilter
    Iterator<String> iter = root.fieldNames();
    String key = iter.next();

    JsonNode arrayNode = root.iterator().next();
    if ( arrayNode == null || arrayNode.isMissingNode() || ! arrayNode.isArray() ) {
        throw new RuntimeException( "Invalid format of LogicalFilter encountered." );
    }

    // pass in our objectCodec so that the subJsonParser knows about our configured Modules and Annotations
    JsonParser subJsonParser = arrayNode.traverse( objectCodec );
    List<QueryFilter4> childrenQueryFilters = subJsonParser.readValueAs( new TypeReference<List<QueryFilter4>>() {} );

    return new LogicalFilter4( QueryParam.valueOf( key ), childrenQueryFilters );
}
 
Example #9
Source File: Ports.java    From docker-java with Apache License 2.0 6 votes vote down vote up
@Override
public Ports deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {

    Ports out = new Ports();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {

        Map.Entry<String, JsonNode> field = it.next();
        if (!field.getValue().equals(NullNode.getInstance())) {
            String hostIp = field.getValue().get(0).get("HostIp").textValue();
            String hostPort = field.getValue().get(0).get("HostPort").textValue();
            out.addPort(Port.makePort(field.getKey(), hostIp, hostPort));
        }
    }
    return out;
}
 
Example #10
Source File: SourceForgeArticleDeserialiser.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SourceForgeArticle deserialize(JsonParser parser,
        DeserializationContext context) throws IOException,
        JsonProcessingException {

    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);
    
    JsonNode attachmentsNode = node.path("attachments");
    SourceForgeAttachment[] attachments = oc.treeToValue(attachmentsNode, SourceForgeAttachment[].class);
    
    SourceForgeArticle article = new SourceForgeArticle();
    article.setArticleNumber(articleNumber++);
    article.setSubject(getText(node, "subject"));
    article.setText(getText(node, "text"));
    article.setUser(getText(node,"author"));
    article.setAttachments(attachments);
    article.setArticleId(getText(node, "slug"));
    article.setDate(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "timestamp"));
    article.setUpdateDate(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "last_edited"));
    article.setReferences(new String[0]);
    return article;
}
 
Example #11
Source File: SourceForgeCommentDeserialiser.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SourceForgeComment deserialize(JsonParser parser,
        DeserializationContext context) throws IOException,
        JsonProcessingException {
    
    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);
    
    JsonNode attachmentsNode = node.path("attachments");
    SourceForgeAttachment[] attachments = oc.treeToValue(attachmentsNode, SourceForgeAttachment[].class);
    
    SourceForgeComment comment = new SourceForgeComment();
    comment.setSubject(getText(node, "subject"));
    comment.setText(getText(node, "text"));
    comment.setCreator(getText(node,"author"));
    comment.setAttachments(attachments);
    comment.setCommentId(getText(node, "slug"));
    comment.setCreationTime(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "timestamp"));
    comment.setUpdateDate(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "last_edited"));
    
    return comment;
}
 
Example #12
Source File: JSonBindingUtils.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Override
public Component deserialize( JsonParser parser, DeserializationContext context ) throws IOException {

	ObjectCodec oc = parser.getCodec();
	JsonNode node = oc.readTree( parser );
	Component component = new Component();

	JsonNode n;
	if(( n = node.get( NAME )) != null )
		component.setName( n.textValue());

	if(( n = node.get( COMP_INSTALLER )) != null )
		component.setInstallerName( n.textValue());

	return component;
}
 
Example #13
Source File: CustomCarDeserializer.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Car deserialize(final JsonParser parser, final DeserializationContext deserializer) throws IOException {
    final Car car = new Car();
    final ObjectCodec codec = parser.getCodec();
    final JsonNode node = codec.readTree(parser);
    try {
        final JsonNode colorNode = node.get("color");
        final String color = colorNode.asText();
        car.setColor(color);
    } catch (final Exception e) {
        Logger.debug("101_parse_exeption: unknown json.");
    }
    return car;
}
 
Example #14
Source File: JSonBindingUtils.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Application deserialize( JsonParser parser, DeserializationContext context ) throws IOException {

	ObjectCodec oc = parser.getCodec();
	JsonNode node = oc.readTree( parser );

	Application application;
	JsonNode n;
	if(( n = node.get( APP_INST_TPL_NAME )) != null ) {
		ApplicationTemplate appTemplate = new ApplicationTemplate();
		appTemplate.setName( n.textValue());

		n = node.get( APP_INST_TPL_VERSION );
		if( n != null )
			appTemplate.setVersion( n.textValue());

		n = node.get( APP_INST_TPL_EEP );
		if( n != null )
			appTemplate.setExternalExportsPrefix( n.textValue());

		application = new Application( appTemplate );

	} else {
		application = new Application( null );
	}

	if(( n = node.get( DISPLAY_NAME )) != null )
		application.setName( n.textValue());
	else if(( n = node.get( NAME )) != null )
		application.setName( n.textValue());

	if(( n = node.get( DESC )) != null )
		application.setDescription( n.textValue());

	return application;
}
 
Example #15
Source File: ResourceDeserializer.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public Resource deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
	ObjectCodec oc = jsonParser.getCodec();
	JsonNode node = oc.readTree(jsonParser);

	final String url = node.asText();

	return this.appResourceCommon.getResource(url);
}
 
Example #16
Source File: VolumesFrom.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Override
public VolumesFrom deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException {

    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    return VolumesFrom.parse(node.asText());

}
 
Example #17
Source File: CoinbaseRecurringPaymentStatus.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public CoinbaseRecurringPaymentStatus deserialize(
    JsonParser jsonParser, final DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  final ObjectCodec oc = jsonParser.getCodec();
  final JsonNode node = oc.readTree(jsonParser);
  final String jsonString = node.textValue();
  return FROM_STRING_HELPER.fromJsonString(jsonString);
}
 
Example #18
Source File: PayloadDeserializerTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldThrowOnNullTree() throws Exception {
    exception.expect(JWTDecodeException.class);
    exception.expectMessage("Parsing the Payload's JSON resulted on a Null map");

    JsonParser parser = mock(JsonParser.class);
    ObjectCodec codec = mock(ObjectCodec.class);
    DeserializationContext context = mock(DeserializationContext.class);

    when(codec.readValue(eq(parser), any(TypeReference.class))).thenReturn(null);
    when(parser.getCodec()).thenReturn(codec);

    deserializer.deserialize(parser, context);
}
 
Example #19
Source File: BitmexFee.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public BitmexFee deserialize(JsonParser jsonParser, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  BigDecimal volume = new BigDecimal(node.path(0).asText());
  BigDecimal fee = new BigDecimal(node.path(1).asText());

  return new BitmexFee(volume, fee);
}
 
Example #20
Source File: CoinbaseCentsDeserializer.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public CoinbaseMoney deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  final ObjectCodec oc = jp.getCodec();
  final JsonNode node = oc.readTree(jp);

  return getCoinbaseMoneyFromCents(node);
}
 
Example #21
Source File: EntityIdDeserializer.java    From Groza with Apache License 2.0 5 votes vote down vote up
@Override
public EntityId deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    ObjectNode node = oc.readTree(jsonParser);
    if (node.has("entityType") && node.has("id")) {
        return EntityIdFactory.getByTypeAndId(node.get("entityType").asText(), node.get("id").asText());
    } else {
        throw new IOException("Missing entityType or id!");
    }
}
 
Example #22
Source File: OrderBookEntryDeserializer.java    From java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public OrderBookEntry deserialize(JsonParser jp, DeserializationContext ctx) throws IOException {
    ObjectCodec oc = jp.getCodec();
    JsonNode node = oc.readTree(jp);
    final String price = node.get(0).asText();
    final String qty = node.get(1).asText();

    OrderBookEntry orderBookEntry = new OrderBookEntry();
    orderBookEntry.setPrice(price);
    orderBookEntry.setQuantity(qty);
    return orderBookEntry;
}
 
Example #23
Source File: CoinbaseCurrencyData.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public CoinbaseCurrency deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {
  ObjectCodec oc = jp.getCodec();
  JsonNode node = oc.readTree(jp);
  String name = node.get("name").asText();
  String id = node.get("id").asText();
  return new CoinbaseCurrency(name, id);
}
 
Example #24
Source File: AudienceJacksonDeserializer.java    From java-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public Audience deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    ObjectCodec codec = parser.getCodec();
    JsonNode node = codec.readTree(parser);

    String id = node.get("id").textValue();
    String name = node.get("name").textValue();

    JsonNode conditionsJson = node.get("conditions");
    conditionsJson = objectMapper.readTree(conditionsJson.textValue());

    Condition conditions = ConditionJacksonDeserializer.<UserAttribute>parseCondition(UserAttribute.class, objectMapper, conditionsJson);

    return new Audience(id, name, conditions);
}
 
Example #25
Source File: CoinbaseCurrency.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public CoinbaseCurrency deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  ObjectCodec oc = jp.getCodec();
  JsonNode node = oc.readTree(jp);
  if (node.isArray()) {
    String name = node.path(0).asText();
    String isoCode = node.path(1).asText();
    return new CoinbaseCurrency(name, isoCode);
  }
  return null;
}
 
Example #26
Source File: OrderBookEntryDeserializer.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public OrderBookEntry deserialize(JsonParser jp, DeserializationContext ctx) throws IOException {
  ObjectCodec oc = jp.getCodec();
  JsonNode node = oc.readTree(jp);
  final String price = node.get(0).asText();
  final String qty = node.get(1).asText();

  OrderBookEntry orderBookEntry = new OrderBookEntry();
  orderBookEntry.setPrice(price);
  orderBookEntry.setQty(qty);
  return orderBookEntry;
}
 
Example #27
Source File: CoinbaseOrder.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public CoinbaseOrderStatus deserialize(JsonParser jsonParser, DeserializationContext ctxt)
    throws IOException, JsonProcessingException {

  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  String jsonString = node.textValue();
  return FROM_STRING_HELPER.fromJsonString(jsonString);
}
 
Example #28
Source File: MyJsonModuleProvider.java    From wisdom with Apache License 2.0 5 votes vote down vote up
public MyJsonModuleProvider() {                                     // <2>
    module = new SimpleModule("My Json Module");
    module.addSerializer(Car.class, new JsonSerializer<Car>() {
        @Override
        public void serialize(Car car, JsonGenerator jsonGenerator,
                              SerializerProvider serializerProvider)
                throws IOException {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("custom", "customized value");
            jsonGenerator.writeStringField("color", car.getColor());
            jsonGenerator.writeStringField("brand", car.getBrand());
            jsonGenerator.writeStringField("model", car.getModel());
            jsonGenerator.writeNumberField("power", car.getPower());
            jsonGenerator.writeEndObject();
        }
    });
    module.addDeserializer(Car.class, new JsonDeserializer<Car>() {
        @Override
        public Car deserialize(
                JsonParser jsonParser,
                DeserializationContext deserializationContext)
                throws IOException {
            ObjectCodec oc = jsonParser.getCodec();
            JsonNode node = oc.readTree(jsonParser);
            String color = node.get("color").asText();
            String brand = node.get("brand").asText();
            String model = node.get("model").asText();
            int power = node.get("power").asInt();
            return new Car(brand, model, power, color);
        }
    });
}
 
Example #29
Source File: MgmtDistributionSetAssignmentsDeserializer.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public MgmtDistributionSetAssignments deserialize(final JsonParser jp, final DeserializationContext ctx)
        throws IOException {
    final MgmtDistributionSetAssignments assignments = new MgmtDistributionSetAssignments();
    final ObjectCodec codec = jp.getCodec();
    final JsonNode node = codec.readTree(jp);
    if (node.isArray()) {
        assignments.addAll(Arrays.asList(codec.treeToValue(node, MgmtDistributionSetAssignment[].class)));
    } else {
        assignments.add(codec.treeToValue(node, MgmtDistributionSetAssignment.class));
    }
    return assignments;
}
 
Example #30
Source File: ContractDeserializer.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Contract deserialize(JsonParser parser, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    ObjectCodec oc = parser.getCodec();
    ObjectNode treeNode = oc.readTree(parser);
    Contract contract = new Contract();
    parseNodeContractInput(childInput(treeNode), contract);
    return contract;
}