com.fasterxml.jackson.databind.JsonNode.isPojo()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中com.fasterxml.jackson.databind.JsonNode.isPojo()方法的一些代码示例,展示了JsonNode.isPojo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.isPojo()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:isPojo

JsonNode.isPojo介绍

[英]Method that can be used to check if the node is a wrapper for a POJO ("Plain Old Java Object" aka "bean". Returns true only for instances of POJONode.
[中]方法,该方法可用于检查节点是否是POJO的包装(“纯旧Java对象”又名“bean”)。仅对POJONode的实例返回true。

代码示例

代码示例来源:origin: redisson/redisson

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: briandilley/jsonrpc4j

return boolean.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type);
if (node.isObject() || node.isPojo()) {
  return !type.isPrimitive() && !String.class.isAssignableFrom(type) &&
      !Number.class.isAssignableFrom(type) && !Boolean.class.isAssignableFrom(type);

代码示例来源:origin: gentics/mesh

@Override
public boolean isExpandedNodeField(String fieldKey) {
  JsonNode field = node.get(fieldKey);
  if (field == null) {
    return false;
  }
  if (field.isObject() && field.has("fields")) {
    return true;
  }
  if (field.isPojo()) {
    return ((POJONode) field).getPojo() instanceof NodeResponse;
  }
  return false;
}

代码示例来源:origin: io.ratpack/ratpack-core

private static <T> T toValue(ObjectCodec codec, JsonNode node, Class<T> valueType) throws JsonProcessingException {
 if (node.isPojo()) {
  Object pojo = ((POJONode) node).getPojo();
  if (valueType.isInstance(pojo)) {
   return valueType.cast(pojo);
  }
 }
 return codec.treeToValue(node, valueType);
}

代码示例来源:origin: gentics/mesh

private BinaryField transformBinaryFieldJsonNode(JsonNode jsonNode, String key) throws JsonProcessingException {
  // Unwrap stored pojos
  if (jsonNode.isPojo()) {
    return pojoNodeToValue(jsonNode, BinaryField.class, key);
  }
  return JsonUtil.getMapper().treeToValue(jsonNode, BinaryFieldImpl.class);
}

代码示例来源:origin: gentics/mesh

private StringField transformStringFieldJsonNode(JsonNode jsonNode, String key) throws JsonProcessingException {
  // Unwrap stored pojos
  if (jsonNode.isPojo()) {
    StringField field = pojoNodeToValue(jsonNode, StringField.class, key);
    if (field == null || field.getString() == null) {
      return null;
    } else {
      return field;
    }
  }
  StringField stringField = new StringFieldImpl();
  if (!jsonNode.isNull() && jsonNode.isTextual()) {
    stringField.setString(jsonNode.textValue());
  }
  if (!jsonNode.isNull() && !jsonNode.isTextual()) {
    throw error(BAD_REQUEST, "The field value for {" + key + "} is not a text value. The value was {" + jsonNode.asText() + "}");
  }
  return stringField;
}

代码示例来源:origin: gentics/mesh

/**
 * Transform the JSON node field into html field POJO.
 * 
 * @param jsonNode
 * @param key
 * @return
 */
private HtmlField transformHtmlFieldJsonNode(JsonNode jsonNode, String key) {
  // Unwrap stored pojos
  if (jsonNode.isPojo()) {
    HtmlField field = pojoNodeToValue(jsonNode, HtmlField.class, key);
    if (field == null || field.getHTML() == null) {
      return null;
    } else {
      return field;
    }
  }
  HtmlField htmlField = new HtmlFieldImpl();
  if (!jsonNode.isNull() && jsonNode.isTextual()) {
    htmlField.setHTML(jsonNode.textValue());
  }
  if (!jsonNode.isNull() && !jsonNode.isTextual()) {
    throw error(BAD_REQUEST, "field_html_error_invalid_type", key, jsonNode.asText());
  }
  return htmlField;
}

代码示例来源:origin: gentics/mesh

/**
 * Transform the JSON node into a response POJO.
 * 
 * @param jsonNode
 * @param key
 * @return
 */
private DateField transformDateFieldJsonNode(JsonNode jsonNode, String key) {
  // Unwrap stored pojos
  if (jsonNode.isPojo()) {
    DateField field = pojoNodeToValue(jsonNode, DateField.class, key);
    if (field == null || field.getDate() == null) {
      return null;
    } else {
      return field;
    }
  }
  DateField dateField = new DateFieldImpl();
  if (!jsonNode.isNull() && jsonNode.isTextual()) {
    dateField.setDate(jsonNode.textValue());
  }
  if (!jsonNode.isNull() && !jsonNode.isTextual()) {
    throw error(BAD_REQUEST, "The field value for date field {" + key + "} is not a string value. The value was {" + jsonNode.asText() + "}");
  }
  return dateField;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

@Override
public byte[] getBinaryValue(Base64Variant b64variant)
  throws IOException, JsonParseException
{
  // Multiple possibilities...
  JsonNode n = currentNode();
  if (n != null) { // binary node?
    byte[] data = n.binaryValue();
    // (or TextNode, which can also convert automatically!)
    if (data != null) {
      return data;
    }
    // Or maybe byte[] as POJO?
    if (n.isPojo()) {
      Object ob = ((POJONode) n).getPojo();
      if (ob instanceof byte[]) {
        return (byte[]) ob;
      }
    }
  }
  // otherwise return null to mark we have no binary content
  return null;
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

@Override
public byte[] getBinaryValue(Base64Variant b64variant)
  throws IOException, JsonParseException
{
  // Multiple possibilities...
  JsonNode n = currentNode();
  if (n != null) { // binary node?
    byte[] data = n.binaryValue();
    // (or TextNode, which can also convert automatically!)
    if (data != null) {
      return data;
    }
    // Or maybe byte[] as POJO?
    if (n.isPojo()) {
      Object ob = ((POJONode) n).getPojo();
      if (ob instanceof byte[]) {
        return (byte[]) ob;
      }
    }
  }
  // otherwise return null to mark we have no binary content
  return null;
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

@Override
public byte[] getBinaryValue(Base64Variant b64variant)
  throws IOException, JsonParseException
{
  // Multiple possibilities...
  JsonNode n = currentNode();
  if (n != null) { // binary node?
    byte[] data = n.binaryValue();
    // (or TextNode, which can also convert automatically!)
    if (data != null) {
      return data;
    }
    // Or maybe byte[] as POJO?
    if (n.isPojo()) {
      Object ob = ((POJONode) n).getPojo();
      if (ob instanceof byte[]) {
        return (byte[]) ob;
      }
    }
  }
  // otherwise return null to mark we have no binary content
  return null;
}

代码示例来源:origin: Nextdoor/bender

@Override
public byte[] getBinaryValue(Base64Variant b64variant)
  throws IOException, JsonParseException
{
  // Multiple possibilities...
  JsonNode n = currentNode();
  if (n != null) { // binary node?
    byte[] data = n.binaryValue();
    // (or TextNode, which can also convert automatically!)
    if (data != null) {
      return data;
    }
    // Or maybe byte[] as POJO?
    if (n.isPojo()) {
      Object ob = ((POJONode) n).getPojo();
      if (ob instanceof byte[]) {
        return (byte[]) ob;
      }
    }
  }
  // otherwise return null to mark we have no binary content
  return null;
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: Nextdoor/bender

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: com.netflix.falcor/falcor-model

@Override
  public void serializeWithType(Atom value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException {
    final JsonNode atom = value.asAtom();
    if (atom == null || atom.isObject() || atom.isPojo() || atom.isArray() || value.getExpires() != null) {
      typeSer.writeTypePrefixForObject(value, gen);
      if (atom != null) {
        gen.writeObjectField("value", value.asAtom());
      }
      if (value.getExpires() != null) {
        gen.writeObjectField("$expires", value.getExpires());
      }
      typeSer.writeTypeSuffixForObject(value, gen);
    } else {
      // Omit type if atom is not an object
      gen.writeTree(value.asAtom());
    }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: com.eclipsesource.jaxrs/jersey-all

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

@Override
public Object getEmbeddedObject()
{
  if (!_closed) {
    JsonNode n = currentNode();
    if (n != null) {
      if (n.isPojo()) {
        return ((POJONode) n).getPojo();
      }
      if (n.isBinary()) {
        return ((BinaryNode) n).binaryValue();
      }
    }
  }
  return null;
}

代码示例来源:origin: gentics/mesh

private NumberField transformNumberFieldJsonNode(JsonNode jsonNode, String key) {
  // Unwrap stored pojos
  if (jsonNode.isPojo()) {
    NumberField field = pojoNodeToValue(jsonNode, NumberField.class, key);
    if (field == null || field.getNumber() == null) {
      return null;
    } else {
      return field;
    }
  }
  NumberField numberField = new NumberFieldImpl();
  if (!jsonNode.isNull() && jsonNode.isNumber()) {
    Number number = jsonNode.numberValue();
    numberField.setNumber(number);
  }
  if (!jsonNode.isNull() && !jsonNode.isNumber()) {
    throw error(BAD_REQUEST, "field_number_error_invalid_type", key, jsonNode.asText());
  }
  return numberField;
}

相关文章