本文整理汇总了Java中org.codehaus.jackson.node.ContainerNode类的典型用法代码示例。如果您正苦于以下问题:Java ContainerNode类的具体用法?Java ContainerNode怎么用?Java ContainerNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerNode类属于org.codehaus.jackson.node包,在下文中一共展示了ContainerNode类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAvroCompositeType
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
private ContainerNode buildAvroCompositeType(String avroRecordTypeName,
final ArrayNode avroFields, boolean isArray, boolean isOptional)
throws Xsd2AvroTranslatorException {
ObjectNode avroRecord = buildAvroRecordType(avroRecordTypeName,
avroFields);
if (isArray) {
ObjectNode avroArray = MAPPER.createObjectNode();
avroArray.put("type", "array");
avroArray.put("items", avroRecord);
return avroArray;
}
if (isOptional) {
ArrayNode typesArray = MAPPER.createArrayNode();
typesArray.add(avroRecord);
typesArray.add("null");
return typesArray;
}
return avroRecord;
}
示例2: visit
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
/**
* Process a regular XML schema element.
*
* @param xmlSchema the input XML schema
* @param xsdElement the XML Schema element to process
* @param level the current level in the elements hierarchy.
* @param avroFields array of fields being populated
* @throws Xsd2AvroTranslatorException if processing fails
*/
private void visit(XmlSchema xmlSchema, final XmlSchemaElement xsdElement,
final int level, final ArrayNode avroFields)
throws Xsd2AvroTranslatorException {
/*
* If this element is referencing another, it might not be useful to
* process it.
*/
if (xsdElement.getRef().getTarget() != null) {
return;
}
log.debug("process started for element = " + xsdElement.getName());
if (xsdElement.getSchemaType() instanceof XmlSchemaComplexType) {
XmlSchemaComplexType xsdType = (XmlSchemaComplexType) xsdElement
.getSchemaType();
int nextLevel = level + 1;
final ArrayNode avroChildrenFields = MAPPER.createArrayNode();
visit(xmlSchema, xsdType, nextLevel, avroChildrenFields);
ContainerNode avroRecordType = buildAvroCompositeType(
getAvroTypeName(xsdType), avroChildrenFields,
xsdElement.getMaxOccurs() > 1,
xsdElement.getMinOccurs() == 0
&& xsdElement.getMaxOccurs() == 1);
ObjectNode avroRecordElement = MAPPER.createObjectNode();
avroRecordElement.put("type", avroRecordType);
avroRecordElement.put("name", getAvroFieldName(xsdElement));
avroFields.add(avroRecordElement);
} else if (xsdElement.getSchemaType() instanceof XmlSchemaSimpleType) {
visit((XmlSchemaSimpleType) xsdElement.getSchemaType(), level,
getAvroFieldName(xsdElement), xsdElement.getMinOccurs(),
xsdElement.getMaxOccurs(), avroFields);
}
log.debug("process ended for element = " + xsdElement.getName());
}
示例3: testToJsonFormatLog
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
@Test
public void testToJsonFormatLog() throws Throwable {
DBAuditMetadataLogEntity amle = new DBAuditMetadataLogEntity("serviceName", "userName",
"impersonator", "ipAddress", "operation", "eventTime", "operationText", "allowed",
"objectType", "component", "databaseName", "tableName", "columnName", "resourcePath");
String jsonAuditLog = amle.toJsonFormatLog();
ContainerNode rootNode = AuditMetadataLogEntity.parse(jsonAuditLog);
assertEntryEquals(rootNode, Constants.LOG_FIELD_SERVICE_NAME, "serviceName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_USER_NAME, "userName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_IMPERSONATOR,
"impersonator");
assertEntryEquals(rootNode, Constants.LOG_FIELD_IP_ADDRESS, "ipAddress");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION, "operation");
assertEntryEquals(rootNode, Constants.LOG_FIELD_EVENT_TIME, "eventTime");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION_TEXT,
"operationText");
assertEntryEquals(rootNode, Constants.LOG_FIELD_ALLOWED, "allowed");
assertEntryEquals(rootNode, Constants.LOG_FIELD_DATABASE_NAME,
"databaseName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_TABLE_NAME, "tableName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_COLUMN_NAME, "columnName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_RESOURCE_PATH,
"resourcePath");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OBJECT_TYPE, "objectType");
}
示例4: parse
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
/**
* For use in tests
*
* @param json incoming JSON to parse
* @return a node tree
* @throws IOException on any parsing problems
*/
public static ContainerNode parse(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper(factory);
JsonNode jsonNode = mapper.readTree(json);
if (!(jsonNode instanceof ContainerNode)) {
throw new IOException("Wrong JSON data: " + json);
}
return (ContainerNode) jsonNode;
}
示例5: testNestedException
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
@Test
public void testNestedException() throws Throwable {
Exception e =
new NoRouteToHostException("that box caught fire 3 years ago");
Exception ioe = new IOException("Datacenter problems", e);
ThrowableInformation ti = new ThrowableInformation(ioe);
Log4Json l4j = new Log4Json();
long timeStamp = Time.now();
String outcome = l4j.toJson(new StringWriter(),
"testNestedException",
timeStamp,
"INFO",
"quoted\"",
"new line\n and {}",
ti)
.toString();
println("testNestedException", outcome);
ContainerNode rootNode = Log4Json.parse(outcome);
assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS,
ioe.getClass().getName());
JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
assertTrue("Not an array: " + node, node.isArray());
node = assertNodeContains(rootNode, Log4Json.DATE);
assertTrue("Not a string: " + node, node.isTextual());
//rather than try and make assertions about the format of the text
//message equalling another ISO date, this test asserts that the hypen
//and colon characters are in the string.
String dateText = node.getTextValue();
assertTrue("No '-' in " + dateText, dateText.contains("-"));
assertTrue("No '-' in " + dateText, dateText.contains(":"));
}
示例6: assertNodeContains
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
private JsonNode assertNodeContains(ContainerNode rootNode, String key) {
JsonNode node = rootNode.get(key);
if (node == null) {
fail("No entry of name \"" + key + "\" found in " + rootNode.toString());
}
return node;
}
示例7: testToJsonFormatLog
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
@Test
public void testToJsonFormatLog() throws Throwable {
Map<String, String> privilegesMap = new HashMap<String, String>();
privilegesMap.put("resourceType1", "resourceName1");
privilegesMap.put("resourceType2", "resourceName2");
privilegesMap.put("resourceType3", "resourceName3");
privilegesMap.put("resourceType4", "resourceName4");
GMAuditMetadataLogEntity gmamle = new GMAuditMetadataLogEntity("serviceName", "userName",
"impersonator", "ipAddress", "operation", "eventTime", "operationText", "allowed",
"objectType", "component", privilegesMap);
String jsonAuditLog = gmamle.toJsonFormatLog();
ContainerNode rootNode = AuditMetadataLogEntity.parse(jsonAuditLog);
assertEntryEquals(rootNode, Constants.LOG_FIELD_SERVICE_NAME, "serviceName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_USER_NAME, "userName");
assertEntryEquals(rootNode, Constants.LOG_FIELD_IMPERSONATOR, "impersonator");
assertEntryEquals(rootNode, Constants.LOG_FIELD_IP_ADDRESS, "ipAddress");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION, "operation");
assertEntryEquals(rootNode, Constants.LOG_FIELD_EVENT_TIME, "eventTime");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OPERATION_TEXT, "operationText");
assertEntryEquals(rootNode, Constants.LOG_FIELD_ALLOWED, "allowed");
assertEntryEquals(rootNode, Constants.LOG_FIELD_OBJECT_TYPE, "objectType");
assertEntryEquals(rootNode, Constants.LOG_FIELD_COMPONENT, "component");
assertEntryEquals(rootNode, "resourceType1", "resourceName1");
assertEntryEquals(rootNode, "resourceType2", "resourceName2");
assertEntryEquals(rootNode, "resourceType3", "resourceName3");
assertEntryEquals(rootNode, "resourceType4", "resourceName4");
}
示例8: assertEntryEquals
import org.codehaus.jackson.node.ContainerNode; //导入依赖的package包/类
void assertEntryEquals(ContainerNode rootNode, String key, String value) {
JsonNode node = assertNodeContains(rootNode, key);
assertEquals(value, node.getTextValue());
}