Java Code Examples for com.fasterxml.jackson.core.JsonParser#getCodec()

The following examples show how to use com.fasterxml.jackson.core.JsonParser#getCodec() . 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: SelfHealingEngine.java    From healenium-web with Apache License 2.0 7 votes vote down vote up
/**
 * Convert raw data to {@code Node}
 * @param parser - JSON reader
 * @return path node
 * @throws IOException
 */
private Node toNode(JsonParser parser) throws IOException {
    ObjectCodec codec = parser.getCodec();
    TreeNode tree = parser.readValueAsTree();
    String tag = codec.treeToValue(tree.path(FieldName.TAG), String.class);
    Integer index = codec.treeToValue(tree.path(FieldName.INDEX), Integer.class);
    String innerText = codec.treeToValue(tree.path(FieldName.INNER_TEXT), String.class);
    String id = codec.treeToValue(tree.path(FieldName.ID), String.class);
    //noinspection unchecked
    Set<String> classes = codec.treeToValue(tree.path(FieldName.CLASSES), Set.class);
    //noinspection unchecked
    Map<String, String> attributes = codec.treeToValue(tree.path(FieldName.OTHER), Map.class);
    return new NodeBuilder()
            //TODO: fix attribute setting, because they override 'id' and 'classes' property
            .setAttributes(attributes)
            .setTag(tag)
            .setIndex(index)
            .setId(id)
            .addContent(innerText)
            .setClasses(classes)
            .build();
}
 
Example 2
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 3
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 4
Source File: SourceForgeForumSearchDeserialiser.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
    public SourceForgeForumSearch deserialize(JsonParser parser,
            DeserializationContext context) throws IOException,
            JsonProcessingException {
//        System.err.println("SourceForgeGetDeserialiser: started");
        ObjectCodec oc = parser.getCodec();
        JsonNode node = oc.readTree(parser);

        SourceForgeForumSearch result = new SourceForgeForumSearch();

        result.setCount(node.get("count").asInt());
//        System.err.println("SourceForgeGetDeserialiser: count " + node.get("count").asInt());

        Iterator<JsonNode> forums = node.path("forums").iterator();
        while (forums.hasNext()) {
            JsonNode forum = forums.next();
            result.addForumId(forum.get("shortname").asInt());
//            System.err.println("SourceForgeGetDeserialiser: forumId " + forum.get("shortname").asInt());
        }

        return result;
    }
 
Example 5
Source File: IPredicateDeserializer.java    From android-uiconductor with Apache License 2.0 6 votes vote down vote up
@Override
public IPredicate deserialize(
    JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
  ObjectMapper objectMapper = (ObjectMapper) jsonParser.getCodec();
  JsonNode node = jsonParser.getCodec().readTree(jsonParser);
  if (node.has(FIELD)) {
    return new QueryField(
        node.get(FIELD).asText(), node.get(OPERATOR).asText(), node.get(VALUE).asText());
  }
  return new Query(
      node.get(CONDITION).asText(),
      Streams.stream(node.withArray(RULES).elements())
          .map(
              child -> {
                try {
                  return objectMapper.treeToValue(child, IPredicate.class);
                } catch (JsonProcessingException e) {
                  // There is no open source compatible way of throwing
                  // checked exceptions in streams. Following advice from
                  // http://shortn/_8Azgkm5zQn
                  throw new IllegalStateException(e);
                }
              })
          .collect(Collectors.toList()));
}
 
Example 6
Source File: StateActionValueDeserializer.java    From slack-client with Apache License 2.0 6 votes vote down vote up
@Override
public StateActionValue deserialize(JsonParser p, DeserializationContext context) throws IOException {
  final StateActionValue.Builder builder = StateActionValue.builder();

  ObjectCodec codec = p.getCodec();
  JsonNode node = codec.readTree(p);

  if (node.has("type")) {
    builder.setBlockElementType(node.get("type").asText());
  }

  if (node.has("value")) {
    builder.setBlockElementValue(node.get("value").asText());
  } else if (node.has("selected_option")) {
    final JsonNode selectedOption = node.get("selected_option");
    final Option option = codec.treeToValue(selectedOption, Option.class);
    builder.setBlockElementValue(option);
  } else if (node.has("selected_date")) {
    builder.setBlockElementValue(LocalDate.parse(node.get("selected_date").asText()));
  }

  return builder.build();
}
 
Example 7
Source File: PredictionStrategyDeserializer.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
@Override
    public Strategy deserialize(
            JsonParser jp, DeserializationContext ctxt)
            throws IOException, JsonProcessingException {
        ObjectMapper mapper = (ObjectMapper) jp.getCodec();
        ObjectNode root = mapper.readTree(jp);
        Class<? extends Strategy> theClass = null;
        Iterator<Map.Entry<String, JsonNode>> elementsIterator =
                root.fields();
        while (elementsIterator.hasNext()) {
            Map.Entry<String, JsonNode> element = elementsIterator.next();
            String name = element.getKey();
            Class<? extends Strategy> possibility = registry.get(name);
            if(possibility!=null){
                theClass = possibility;
//                break;
            }
        }
        if (registry == null) {
            return null;
        }
        return mapper.treeToValue(root, theClass);
    }
 
Example 8
Source File: BeakerCodeCellListDeserializer.java    From beakerx with Apache License 2.0 6 votes vote down vote up
@Override
public BeakerCodeCellList deserialize(JsonParser jp, DeserializationContext ctxt) 
    throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper)jp.getCodec();
  JsonNode node = mapper.readTree(jp);
  
  List<CodeCell> l = new ArrayList<CodeCell>();
  if (node.isArray()) {
    for (JsonNode o : node) {
      Object obj = objectSerializerProvider.deserialize(o, mapper);
      if (obj instanceof CodeCell)
        l.add((CodeCell) obj);
    }
  }
  
  BeakerCodeCellList r = new BeakerCodeCellList();
  r.theList = l;
  return r;
}
 
Example 9
Source File: NamespaceBindingDeserializer.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public NamespaceBinding deserialize(JsonParser jp, DeserializationContext ctxt) 
    throws IOException, JsonProcessingException {
  ObjectMapper mapper = (ObjectMapper)jp.getCodec();
  JsonNode node = mapper.readTree(jp);
  String name = node.get("name").asText();
  String session = node.get("session").asText();
  Boolean defined = node.get("defined").asBoolean();
  JsonNode o = node.get("value");

  Object obj = objectSerializerProvider.deserialize(o, mapper);
  return new NamespaceBinding(name,session,obj,defined);
}
 
Example 10
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 11
Source File: ArrayOrString.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayOrString deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  ArrayOrString arrayOrString;
  if (node.isArray()) {
    List<String> elements = new ArrayList<>();
    node.elements().forEachRemaining(n -> elements.add(n.asText()));
    arrayOrString = new ArrayOrString(elements);
  } else {
    arrayOrString = new ArrayOrString(node.asText());
  }
  return arrayOrString;
}
 
Example 12
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 13
Source File: AreaDeserializer.java    From Mosaic with Apache License 2.0 5 votes vote down vote up
@Override
   public Rectangle2D.Double deserialize(JsonParser jsonParser, 
       DeserializationContext deserializationContext) throws IOException {
	
	ObjectCodec oc = jsonParser.getCodec();
       JsonNode node = oc.readTree(jsonParser);
       
       String[] params = node.get(KEY_SURFACE_BOUNDS).asText().split(CELL_PTRN);
       return new Rectangle2D.Double(
       	Double.parseDouble(params[X - 1]),
       	Double.parseDouble(params[Y - 1]),
       	Double.parseDouble(params[W - 1]),
       	Double.parseDouble(params[H - 1]));
}
 
Example 14
Source File: CommandJson.java    From concursus with MIT License 5 votes vote down vote up
private BiFunction<JsonNode, Type, Object> makeDeserialiser(ObjectMapper mapper) {
    final TypeFactory typeFactory = mapper.getTypeFactory();
    return (node, type) -> {
        JavaType javaType = typeFactory.constructType(type);
        try {
            final JsonParser jsonParser = mapper.treeAsTokens(node);
            final ObjectCodec codec = jsonParser.getCodec();

            return codec.readValue(jsonParser, javaType);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    };
}
 
Example 15
Source File: Duration.java    From istio-java-api with Apache License 2.0 5 votes vote down vote up
@Override
public Duration deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);
    final Period period = FORMATTER.parsePeriod(node.asText());
    return new Duration(0, (long) period.toStandardSeconds().getSeconds());
}
 
Example 16
Source File: JSonBindingUtils.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ApplicationTemplate deserialize( JsonParser parser, DeserializationContext context ) throws IOException {

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

	JsonNode n;
	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());

	if(( n = node.get( VERSION )) != null )
		application.setVersion( n.textValue());

	if(( n = node.get( EEP )) != null )
		application.setExternalExportsPrefix( n.textValue());

	if(( n = node.get( APP_TPL_TAGS )) != null ) {
		for( JsonNode arrayNodeItem : n )
			application.addTag( arrayNodeItem.textValue());
	}

	return application;
}
 
Example 17
Source File: FieldModule.java    From testrail-api-java-client with MIT License 5 votes vote down vote up
@Override
public Field deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
    Field field = (Field) defaultDeserializer.deserialize(jsonParser, deserializationContext);
    ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec();
    // set type
    field.setType(Field.Type.getType(field.getTypeId()));
    for (Field.Config config : field.getConfigs()) {
        // update options to correct type implementations
        config.setOptions(mapper.convertValue(config.getOptions(), field.getType().getOptionsClass()));
    }
    return field;
}
 
Example 18
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 19
Source File: GeometryDeserializer.java    From jackson-datatype-jts with Apache License 2.0 4 votes vote down vote up
@Override
public T deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode root = oc.readTree(jsonParser);
    return geometryParser.geometryFromJson(root);
}
 
Example 20
Source File: SourceForgeTicketDeserialiser.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public SourceForgeTicket deserialize(JsonParser parser,
        DeserializationContext context) throws IOException,
        JsonProcessingException {
    ObjectCodec oc = parser.getCodec();
    JsonNode node = oc.readTree(parser);
    
    node = node.get("ticket");
    
    SourceForgeTicket ticket = new SourceForgeTicket();
    
    JsonNode attachmentsNode = node.path("attachments");
    SourceForgeAttachment[] attachments = oc.treeToValue(attachmentsNode, SourceForgeAttachment[].class);
    
    JsonNode labelsNode = node.path("labels");
    String[] labels = oc.treeToValue(labelsNode, String[].class);
    
    String bugId = getText(node, "ticket_num");
       
    ticket.setBugId(bugId);
    ticket.setAssignee(getText(node, "assigned_to"));
    ticket.setAssigneeId(getText(node, "assigned_to_id"));
    ticket.setAttachments(attachments);
    ticket.setCommentsUrl(getText(node, "discussion_thread_url"));
    ticket.setCreationTime(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "created_date"));
    ticket.setCreator(getText(node, "reported_by"));
    ticket.setCreatorId(getText(node, "reported_by_id"));
    ticket.setDescription(getText(node, "description"));
    ticket.setInternalId(getText(node, "_id"));
    ticket.setLabels(labels);
    ticket.setPrivate(getBoolean(node, "private"));
    ticket.setStatus(getText(node, "status"));
    ticket.setSummary(getText(node, "summary"));
    ticket.setUpdateDate(getDate(node, SourceForgeConstants.RESPONSE_DATE_FORMATTER, "mod_date"));
    ticket.setVotesDown(getInteger(node, "votes_down"));
    ticket.setVotesUp(getInteger(node, "votes_up"));
    
    JsonNode commentsNode = node.path("discussion_thread").path("posts");
    SourceForgeComment[] comments = oc.treeToValue(commentsNode, SourceForgeComment[].class);
    for (SourceForgeComment comment: comments) {
        comment.setBugId(bugId);
        ticket.getComments().add(comment);
    }
    
    return ticket;
}