本文整理了Java中play.libs.Json.mapper()
方法的一些代码示例,展示了Json.mapper()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.mapper()
方法的具体详情如下:
包路径:play.libs.Json
类名称:Json
方法名:mapper
[英]Gets the ObjectMapper used to serialize and deserialize objects to and from JSON values. This can be set to a custom implementation using Json.setObjectMapper.
[中]获取用于在JSON值之间序列化和反序列化对象的ObjectMapper。可以使用Json将其设置为自定义实现。setObjectMapper。
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Creates a new empty ObjectNode.
* @return new empty ObjectNode.
*/
public static ObjectNode newObject() {
return mapper().createObjectNode();
}
代码示例来源:origin: com.typesafe.play/play
/**
* Creates a new empty ObjectNode.
* @return new empty ObjectNode.
*/
public static ObjectNode newObject() {
return mapper().createObjectNode();
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Creates a new empty ObjectNode.
* @return new empty ObjectNode.
*/
public static ObjectNode newObject() {
return mapper().createObjectNode();
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Parses a byte array representing a json, and return it as a JsonNode.
* @param src the JSON input bytes.
* @return the JSON node.
*/
public static JsonNode parse(byte[] src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Parses a InputStream representing a json, and return it as a JsonNode.
* @param src the JSON input stream.
* @return the JSON node.
*/
public static JsonNode parse(java.io.InputStream src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Converts an object to JsonNode.
*
* @param data Value to convert in Json.
* @return the JSON node.
*/
public static JsonNode toJson(final Object data) {
try {
return mapper().valueToTree(data);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Parses a byte array representing a json, and return it as a JsonNode.
* @param src the JSON input bytes.
* @return the JSON node.
*/
public static JsonNode parse(byte[] src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Parses a String representing a json, and return it as a JsonNode.
* @param src the JSON string.
* @return the JSON node.
*/
public static JsonNode parse(String src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Parses a byte array representing a json, and return it as a JsonNode.
* @param src the JSON input bytes.
* @return the JSON node.
*/
public static JsonNode parse(byte[] src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Parses a String representing a json, and return it as a JsonNode.
* @param src the JSON string.
* @return the JSON node.
*/
public static JsonNode parse(String src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Converts an object to JsonNode.
*
* @param data Value to convert in Json.
* @return the JSON node.
*/
public static JsonNode toJson(final Object data) {
try {
return mapper().valueToTree(data);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Parses a InputStream representing a json, and return it as a JsonNode.
* @param src the JSON input stream.
* @return the JSON node.
*/
public static JsonNode parse(java.io.InputStream src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Parses a InputStream representing a json, and return it as a JsonNode.
* @param src the JSON input stream.
* @return the JSON node.
*/
public static JsonNode parse(java.io.InputStream src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Parses a String representing a json, and return it as a JsonNode.
* @param src the JSON string.
* @return the JSON node.
*/
public static JsonNode parse(String src) {
try {
return mapper().readTree(src);
} catch(Throwable t) {
throw new RuntimeException(t);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Converts an object to JsonNode.
*
* @param data Value to convert in Json.
* @return the JSON node.
*/
public static JsonNode toJson(final Object data) {
try {
return mapper().valueToTree(data);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Converts a JsonNode to a Java value
*
* @param <A> the type of the return value.
* @param json Json value to convert.
* @param clazz Expected Java value type.
* @return the return value.
*/
public static <A> A fromJson(JsonNode json, Class<A> clazz) {
try {
return mapper().treeToValue(json, clazz);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Creates a new empty ArrayNode.
* @return a new empty ArrayNode.
*/
public static ArrayNode newArray() {
return mapper().createArrayNode();
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Creates a new empty ArrayNode.
* @return a new empty ArrayNode.
*/
public static ArrayNode newArray() {
return mapper().createArrayNode();
}
代码示例来源:origin: com.typesafe.play/play
/**
* Creates a new empty ArrayNode.
* @return a new empty ArrayNode.
*/
public static ArrayNode newArray() {
return mapper().createArrayNode();
}
代码示例来源:origin: com.typesafe.play/play_2.12
private static String generateJson(Object o, boolean prettyPrint, boolean escapeNonASCII) {
try {
ObjectWriter writer = mapper().writer();
if (prettyPrint) {
writer = writer.with(SerializationFeature.INDENT_OUTPUT);
}
if (escapeNonASCII) {
writer = writer.with(Feature.ESCAPE_NON_ASCII);
}
return writer.writeValueAsString(o);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!