本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.createObjectNode方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.createObjectNode方法的具体用法?Java ObjectMapper.createObjectNode怎么用?Java ObjectMapper.createObjectNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.createObjectNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: includeElementFieldWithWeight
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void includeElementFieldWithWeight(String dbName, String field_name, String namespace, String elementName, double weight, String attrNS_URI, String attr_localname, String attr_value) throws Exception{
ObjectMapper mapper = new ObjectMapper();
// ObjectNode mainNode = mapper.createObjectNode();
ObjectNode childNode = mapper.createObjectNode();
ArrayNode arrNode = mapper.createArrayNode();
ObjectNode childNodeObject = mapper.createObjectNode();
childNodeObject.put( "namespace-uri", namespace);
childNodeObject.put( "localname", elementName);
childNodeObject.put("weight", weight);
// These 3 are new fields that have been added as of 8.0.2 from 03/20/2015 in the Management API.
childNodeObject.put( "attribute-namespace-uri", attrNS_URI);
childNodeObject.put( "attribute-localname", attr_localname);
childNodeObject.put( "attribute-value", attr_value);
arrNode.add(childNodeObject);
childNode.putArray("included-element").addAll(arrNode);
//System.out.println( childNode.toString());
setDatabaseFieldProperties(dbName,field_name,"included-element",childNode);
}
示例2: arrayOfPrimitivesProducesCollectionOfWrapperTypes
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void arrayOfPrimitivesProducesCollectionOfWrapperTypes() {
JCodeModel codeModel = new JCodeModel();
JPackage jpackage = codeModel._package(getClass().getPackage().getName());
ObjectMapper mapper = new ObjectMapper();
ObjectNode itemsNode = mapper.createObjectNode();
itemsNode.put("type", "number");
ObjectNode propertyNode = mapper.createObjectNode();
propertyNode.set("uniqueItems", BooleanNode.FALSE);
propertyNode.set("items", itemsNode);
Schema schema = mock(Schema.class);
when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray"));
when(config.isUsePrimitives()).thenReturn(true);
when(config.isUseDoubleNumbers()).thenReturn(true);
JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
assertThat(propertyType, notNullValue());
assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName()));
}
示例3: getAuthorisationUrl
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private String getAuthorisationUrl(BrightspaceAppContext appContext, String forwardUrl, @Nullable String postfixKey)
{
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode stateJson = mapper.createObjectNode();
stateJson.put(BrightspaceConnectorConstants.STATE_KEY_FORWARD_URL, forwardUrl);
if( postfixKey != null )
{
stateJson.put(BrightspaceConnectorConstants.STATE_KEY_POSTFIX_KEY, postfixKey);
}
URI uri;
try
{
uri = appContext.createWebUrlForAuthentication(
URI.create(institutionService.institutionalise(BrightspaceConnectorConstants.AUTH_URL)),
encrypt(mapper.writeValueAsString(stateJson)));
}
catch( JsonProcessingException e )
{
throw Throwables.propagate(e);
}
return uri.toString();
}
示例4: jsonPorts
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Produces JSON array containing ports of the specified device.
*
* @param service device service
* @param mapper object mapper
* @param device infrastructure devices
* @return JSON array
*/
public JsonNode jsonPorts(DeviceService service, ObjectMapper mapper, Device device) {
ObjectNode result = mapper.createObjectNode();
ArrayNode ports = mapper.createArrayNode();
for (Port port : service.getPorts(device.id())) {
if (isIncluded(port)) {
ports.add(mapper.createObjectNode()
.put("port", portName(port.number()))
.put("isEnabled", port.isEnabled())
.put("type", port.type().toString().toLowerCase())
.put("portSpeed", port.portSpeed())
.set("annotations", annotations(mapper, port.annotations())));
}
}
result.set("device", jsonForEntity(device, Device.class));
result.set("ports", ports);
return result;
}
示例5: handlerGroupedFields
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private ObjectNode handlerGroupedFields(ObjectMapper mapper, Field[] declaredFields,
Map<Field, JsonNode> sortedNodes) {
Predicate<? super Field> checkFieldSetAnnotation = field -> field.isAnnotationPresent(FieldSet.class);
Map<String, List<JsonNode>> groupedFields = new LinkedHashMap<>();
Arrays.stream(declaredFields).filter(checkFieldSetAnnotation)
.forEach(field -> groupFieldsByTab(sortedNodes, field, groupedFields));
ArrayNode groups = mapper.createArrayNode();
ObjectNode tabsNode = mapper.createObjectNode();
tabsNode.put(KEY_TYPE, KEY_FIELDSET);
tabsNode.set(KEY_ITEMS, groups);
return tabsNode;
}
示例6: getState
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public JsonNode getState() {
ObjectMapper mapper = new ObjectMapper();
ObjectNode state = mapper.createObjectNode();
state.put("name", this.getClass().getSimpleName());
state.put("rows", this.rows);
state.put("columns", this.columns);
ArrayNode boardState = state.putArray("board");
int[][] board = this.getBoard();
for (int column = 0; column < this.columns; column++) {
ArrayNode columnState = boardState.addArray();
for (int row = 0; row < this.rows; row++) {
columnState.add(board[column][row]);
}
}
state.put("turn", this.currentPlayer);
state.put("ended", this.ended);
state.put("winner", this.winner);
return state;
}
示例7: applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName() {
Answer<String> firstArgAnswer = new FirstArgAnswer<String>();
when(nameHelper.getFieldName(anyString(), Matchers.any(JsonNode.class))).thenAnswer(firstArgAnswer);
when(nameHelper.replaceIllegalCharacters(anyString())).thenAnswer(firstArgAnswer);
when(nameHelper.normalizeName(anyString())).thenAnswer(firstArgAnswer);
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode();
arrayNode.add("open");
arrayNode.add("closed");
ObjectNode enumNode = objectMapper.createObjectNode();
enumNode.put("type", "string");
enumNode.set("enum", arrayNode);
// We're always a string for the purposes of this test
when(typeRule.apply("status", enumNode, jpackage, schema))
.thenReturn(jpackage.owner()._ref(String.class));
JType result1 = rule.apply("status", enumNode, jpackage, schema);
JType result2 = rule.apply("status", enumNode, jpackage, schema);
assertThat(result1.fullName(), is("org.jsonschema2pojo.rules.Status"));
assertThat(result2.fullName(), is("org.jsonschema2pojo.rules.Status_"));
}
示例8: getCollectionNode
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static ObjectNode getCollectionNode(String... collections){
ObjectMapper mapper= new ObjectMapper();
ObjectNode mNode = mapper.createObjectNode();
ArrayNode aNode = mapper.createArrayNode();
for(String c : collections){
aNode.add(c);
}
mNode.withArray("collection").addAll(aNode);
return mNode;
}
示例9: parseJsonContent
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static JsonNode parseJsonContent(byte[] rawJsonContent, ObjectMapper mapper) {
if (rawJsonContent == null) {
return mapper.createObjectNode();
}
try {
return mapper.readTree(rawJsonContent);
} catch (Exception e) {
LOG.info("Unable to parse HTTP response content", e);
return mapper.createObjectNode();
}
}
示例10: handleActionsAnnotation
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void handleActionsAnnotation(ObjectMapper mapper, Class<? extends Serializable> formDto,
ArrayNode formDefinition) {
ObjectNode groupedActionsNode = mapper.createObjectNode();
buildActions(mapper, formDto, formDefinition);
buildGroupedActions(mapper, formDto, groupedActionsNode, formDefinition);
}
示例11: queryAclRule
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Get all ACL rules.
* Returns array of all ACL rules.
*
* @return 200 OK
*/
@GET
public Response queryAclRule() {
List<AclRule> rules = get(AclService.class).getAclRules();
ObjectMapper mapper = new ObjectMapper();
ObjectNode root = mapper.createObjectNode();
ArrayNode arrayNode = mapper.createArrayNode();
for (AclRule rule : rules) {
ObjectNode node = mapper.createObjectNode();
node.put("id", rule.id().toString());
if (rule.srcIp() != null) {
node.put("srcIp", rule.srcIp().toString());
}
if (rule.dstIp() != null) {
node.put("dstIp", rule.dstIp().toString());
}
if (rule.ipProto() != 0) {
switch (rule.ipProto()) {
case IPv4.PROTOCOL_ICMP:
node.put("ipProto", "ICMP");
break;
case IPv4.PROTOCOL_TCP:
node.put("ipProto", "TCP");
break;
case IPv4.PROTOCOL_UDP:
node.put("ipProto", "UDP");
break;
default:
break;
}
}
if (rule.dstTpPort() != 0) {
node.put("dstTpPort", rule.dstTpPort());
}
node.put("action", rule.action().toString());
arrayNode.add(node);
}
root.set("aclRules", arrayNode);
return Response.ok(root.toString(), MediaType.APPLICATION_JSON_TYPE).build();
}
示例12: validateAndAddFieldValue
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static void validateAndAddFieldValue(String type, String fieldValue, String fieldName, String errorMessage,
JsonNode tmp) throws IllegalAccessException {
// Add count variable for loop....
final ObjectMapper mapper = new ObjectMapper();
final ObjectNode parameter = mapper.createObjectNode();
parameter.put("type", type);
if (type == "int") {
parameter.put("defaultValue", Integer.parseInt(fieldValue));
} else {
parameter.put("defaultValue", fieldValue);
}
ObjectNode.class.cast(tmp.get("parameters")).replace(fieldName, parameter);
}
示例13: execute
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
protected void execute() {
IntentMetricsService service = get(IntentMetricsService.class);
if (outputJson()) {
ObjectMapper mapper = new ObjectMapper()
.registerModule(new MetricsModule(TimeUnit.SECONDS,
TimeUnit.MILLISECONDS,
false));
ObjectNode result = mapper.createObjectNode();
result = json(mapper, result, "intentSubmitted",
service.intentSubmittedEventMetric());
result = json(mapper, result, "intentInstalled",
service.intentInstalledEventMetric());
result = json(mapper, result, "intentFailed",
service.intentFailedEventMetric());
result = json(mapper, result, "intentWithdrawRequested",
service.intentWithdrawRequestedEventMetric());
result = json(mapper, result, "intentWithdrawn",
service.intentWithdrawnEventMetric());
result = json(mapper, result, "intentPurged",
service.intentPurgedEventMetric());
print("%s", result);
} else {
printEventMetric("Submitted",
service.intentSubmittedEventMetric());
printEventMetric("Installed",
service.intentInstalledEventMetric());
printEventMetric("Failed",
service.intentFailedEventMetric());
printEventMetric("Withdraw Requested",
service.intentWithdrawRequestedEventMetric());
printEventMetric("Withdrawn",
service.intentWithdrawnEventMetric());
printEventMetric("Purged",
service.intentPurgedEventMetric());
}
}
示例14: buildValueDefinition
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void buildValueDefinition(ObjectMapper comboMapper, ArrayNode titlesMap, String value) {
ObjectNode entry = comboMapper.createObjectNode();
String upperCasedValue = value.toUpperCase();
String lowerCasedValue = value.toLowerCase();
if (value.equals(upperCasedValue)) {
entry.put("name", value.toLowerCase());
} else if (value.equals(lowerCasedValue)) {
entry.put("name", value.replace(value.substring(0, 1), value.substring(0, 1).toUpperCase()));
} else {
entry.put("name", value);
}
entry.put("value", value);
titlesMap.add(entry);
}
示例15: convert
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public ObjectNode convert(ObjectMapper mapper, Limit operator, Integer inputId) {
ObjectNode limitNode = mapper.createObjectNode();
limitNode.put("op", "limit");
limitNode.put("input", inputId);
limitNode.put("first", operator.first);
limitNode.put("last", operator.last);
return limitNode;
}