Java Code Examples for com.fasterxml.jackson.databind.node.BooleanNode#valueOf()

The following examples show how to use com.fasterxml.jackson.databind.node.BooleanNode#valueOf() . 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: ObjectToJsonNode.java    From yosegi with Apache License 2.0 6 votes vote down vote up
/**
 * Judge Java objects and create JsonNode.
 */
public static JsonNode get( final Object obj ) throws IOException {
  if ( obj instanceof PrimitiveObject ) {
    return PrimitiveObjectToJsonNode.get( (PrimitiveObject)obj );
  } else if ( obj instanceof String ) {
    return new TextNode( (String)obj );
  } else if ( obj instanceof Boolean ) {
    return BooleanNode.valueOf( (Boolean)obj );
  } else if ( obj instanceof Short ) {
    return IntNode.valueOf( ( (Short)obj ).intValue() );
  } else if ( obj instanceof Integer ) {
    return IntNode.valueOf( (Integer)obj );
  } else if ( obj instanceof Long ) {
    return new LongNode( (Long)obj );
  } else if ( obj instanceof Float ) {
    return new DoubleNode( ( (Float)obj ).doubleValue() );
  } else if ( obj instanceof Double ) {
    return new DoubleNode( (Double)obj );
  } else if ( obj instanceof byte[] ) {
    return new BinaryNode( (byte[])obj );
  } else if ( obj == null ) {
    return NullNode.getInstance();
  } else {
    return new TextNode( obj.toString() );
  }
}
 
Example 2
Source File: PrimitiveObjectToJsonNode.java    From yosegi with Apache License 2.0 5 votes vote down vote up
/**
 * Convert PrimitiveObject to JsonNode.
 */
public static JsonNode get( final PrimitiveObject obj ) throws IOException {
  if ( obj == null ) {
    return NullNode.getInstance();
  }
  switch ( obj.getPrimitiveType() ) {
    case BOOLEAN:
      return BooleanNode.valueOf( obj.getBoolean() );
    case BYTE:
      return IntNode.valueOf( obj.getInt() );
    case SHORT:
      return IntNode.valueOf( obj.getInt() );
    case INTEGER:
      return IntNode.valueOf( obj.getInt() );
    case LONG:
      return new LongNode( obj.getLong() );
    case FLOAT:
      return new DoubleNode( obj.getDouble() );
    case DOUBLE:
      return new DoubleNode( obj.getDouble() );
    case STRING:
      return new TextNode( obj.getString() );
    case BYTES:
      return new BinaryNode( obj.getBytes() );
    default:
      return NullNode.getInstance();
  }
}
 
Example 3
Source File: Serializer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public JsonNode serialize(Boolean object) {
    return BooleanNode.valueOf(object);
}
 
Example 4
Source File: JsonConverter.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public JsonNode toJson(Object object) throws IOException {
	if (object instanceof SBase) {
		SBase base = (SBase) object;
		ObjectNode jsonObject = OBJECT_MAPPER.createObjectNode();
		jsonObject.put("__type", base.getSClass().getSimpleName());
		for (SField field : base.getSClass().getAllFields()) {
			jsonObject.set(field.getName(), toJson(base.sGet(field)));
		}
		return jsonObject;
	} else if (object instanceof Collection) {
		Collection<?> collection = (Collection<?>) object;
		ArrayNode jsonArray = OBJECT_MAPPER.createArrayNode();
		for (Object value : collection) {
			jsonArray.add(toJson(value));
		}
		return jsonArray;
	} else if (object instanceof Date) {
		return new LongNode(((Date) object).getTime());
	} else if (object instanceof DataHandler) {
		DataHandler dataHandler = (DataHandler) object;
		InputStream inputStream = dataHandler.getInputStream();
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		IOUtils.copy(inputStream, out);
		return new TextNode(new String(Base64.encodeBase64(out.toByteArray()), Charsets.UTF_8));
	} else if (object instanceof Boolean) {
		return BooleanNode.valueOf((Boolean) object);
	} else if (object instanceof String) {
		return new TextNode((String) object);
	} else if (object instanceof Long) {
		return new LongNode((Long) object);
	} else if (object instanceof UUID) {
		return new TextNode(((UUID) object).toString());
	} else if (object instanceof Integer) {
		return new IntNode((Integer) object);
	} else if (object instanceof Double) {
		return new DoubleNode((Double) object);
	} else if (object instanceof Float) {
		return new FloatNode((Float) object);
	} else if (object instanceof Enum) {
		return new TextNode(object.toString());
	} else if (object == null) {
		return NullNode.getInstance();
	} else if (object instanceof byte[]) {
		byte[] data = (byte[]) object;
		return new TextNode(new String(Base64.encodeBase64(data), Charsets.UTF_8));
	}
	throw new UnsupportedOperationException(object.getClass().getName());
}
 
Example 5
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Sets boolean on the specific json pointer.
 *
 * @param ptr    json pointer
 * @param isTrue boolean to set
 * @throws WorkflowException workflow exception
 */
public void setAt(JsonPointer ptr, Boolean isTrue) throws WorkflowException {
    BooleanNode booleanNode = BooleanNode.valueOf(isTrue);
    attach(ptr, booleanNode);
}