Refine search
Tag tag; Tag customTag = classTags.get(javaBean.getClass()); tag = customTag != null ? customTag : new Tag(javaBean.getClass()); MappingNode node = new MappingNode(tag, value, FlowStyle.AUTO); representedObjects.put(javaBean, node); DumperOptions.FlowStyle bestStyle = FlowStyle.FLOW; continue; if (!((ScalarNode) tuple.getKeyNode()).isPlain()) { bestStyle = FlowStyle.BLOCK; Node nodeValue = tuple.getValueNode(); if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).isPlain())) { bestStyle = FlowStyle.BLOCK; node.setFlowStyle(defaultFlowStyle); } else { node.setFlowStyle(bestStyle);
keyNode = (ScalarNode) tuple.getKeyNode(); } else { throw new YAMLException( "Keys must be scalars but found: " + tuple.getKeyNode()); keyNode.setType(String.class); String key = (String) constructObject(keyNode); try { TypeDescription memberDescription = typeDefinitions.get(beanType); if (valueNode.getNodeId() == NodeId.sequence) { Class<?> t = arguments[0]; SequenceNode snode = (SequenceNode) valueNode; Class<?> t = arguments[0]; MappingNode mnode = (MappingNode) valueNode; mnode.setOnlyKeyType(t); : constructObject(valueNode); if (property.getType() == String.class && Tag.BINARY.equals(valueNode.getTag()) && value instanceof byte[]) { value = new String((byte[]) value);
} else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node .getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) {
public boolean useClassConstructor() { if (useClassConstructor == null) { if (!tag.isSecondary() && resolved && !Object.class.equals(type) && !tag.equals(Tag.NULL)) { return true; } else if (tag.isCompatible(getType())) { // the tag is compatible with the runtime class // the tag will be ignored return true; } else { return false; } } return useClassConstructor.booleanValue(); }
/** * Ensure that the stream contains a single document and construct it * * @param type the class of the instance being created * @return constructed instance * @throws ComposerException in case there are more documents in the stream */ public Object getSingleData(Class<?> type) { // Ensure that the stream contains a single document and construct it Node node = composer.getSingleNode(); if (node != null && !Tag.NULL.equals(node.getTag())) { if (Object.class != type) { node.setTag(new Tag(type)); } else if (rootTag != null) { node.setTag(rootTag); } return constructDocument(node); } return null; }
@Override @SneakyThrows protected Object constructObject(Node node) { Class<?> target = node.getType(); if (target == Object.class && node.getTag().startsWith(Tag.PREFIX) && !noClass.contains(node.getTag())) { try { target = Class.forName(node.getTag().getClassName()); } catch (ClassNotFoundException ignored) { for (Subtype subtype : subtypes) { if (!subtype.tag().isEmpty()) { if (subtype.tag().equals(node.getTag().getValue())) { node.setType(subtype.type()); node.setTag(new Tag(subtype.type())); defaultType = null; break TypeSelection; for (NodeTuple tuple : ((MappingNode) node).getValue()) { if (tuple.getKeyNode() instanceof ScalarNode) { tuple.getKeyNode().setType(String.class); String key = (String) constructObject(tuple.getKeyNode()); if (subtype.property().equals(key)) { if (tuple.getValueNode() instanceof ScalarNode) { if (((ScalarNode) tuple.getValueNode()).getValue().equals(subtype.value())) { node.setType(subtype.type()); node.setTag(new Tag(subtype.type())); defaultType = null; break TypeSelection; node.setType(defaultType);
Iterator<NodeTuple> iter = node.getValue().iterator(); while (iter.hasNext()) { final NodeTuple nodeTuple = iter.next(); final Node keyNode = nodeTuple.getKeyNode(); final Node valueNode = nodeTuple.getValueNode(); if (keyNode.getTag().equals(Tag.MERGE)) { iter.remove(); switch (valueNode.getNodeId()) { case mapping: MappingNode mn = (MappingNode) valueNode; if (!(subnode instanceof MappingNode)) { throw new ConstructorException("while constructing a mapping", node.getStartMark(), "expected a mapping for merging, but found " + subnode.getNodeId(), subnode.getStartMark()); default: throw new ConstructorException("while constructing a mapping", node.getStartMark(), "expected a mapping or list of mappings for merging, but found " + valueNode.getNodeId(),
for (int i = 0; i < resourceNode.getValue().size(); i++) NodeTuple resourceTuple = resourceNode.getValue().get(i); if (resourceTuple.getKeyNode().getNodeId() != scalar) String key = ((ScalarNode) resourceTuple.getKeyNode()).getValue(); if (key.equals(RESOURCE_TYPE_USE_KEY)) templateReferences.typeReference = cloneNode(resourceTuple.getValueNode(), new HashMap<String, String>()); removeParametersFromTemplateCall(resourceTuple); Node actionNode = resourceTuple.getValueNode(); if (actionNode.getTag().equals(Tag.NULL)) else if (actionNode.getTag().equals(INCLUDE_TAG)) resourceNode.getValue().remove(i); resourceNode.getValue().add(i, new NodeTuple(resourceTuple.getKeyNode(), actionNode)); for (NodeTuple actionTuple : ((MappingNode) actionNode).getValue()) String actionTupleKey = ((ScalarNode) actionTuple.getKeyNode()).getValue(); if (actionTupleKey.equals(TRAIT_USE_KEY) && expect(actionTuple.getValueNode(), sequence))
protected void processDuplicateKeys(MappingNode node) { List<NodeTuple> nodeValue = node.getValue(); Map<Object, Integer> keys = new HashMap<Object, Integer>(nodeValue.size()); TreeSet<Integer> toRemove = new TreeSet<Integer>(); int i = 0; for (NodeTuple tuple : nodeValue) { Node keyNode = tuple.getKeyNode(); if (!keyNode.getTag().equals(Tag.MERGE)) { Object key = constructObject(keyNode); if (key != null) { node.getStartMark(), "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e); if (prevIndex != null) { if (!isAllowDuplicateKeys()) { throw new DuplicateKeyException(node.getStartMark(), key, tuple.getKeyNode().getStartMark());
private Node resolveInclude(Node node, Tag tag) { if (node.getNodeId() == scalar && node.getTag().equals(INCLUDE_TAG)) { if (tag != null && tag.startsWith(INCLUDE_APPLIED_TAG)) { // for multiple levels of includes in the same template recalculate path using // parent include applied tag path ScalarNode scalarNode = (ScalarNode) node; String parentPath = includeResolver.getContextPath().resolveRelativePath(tag); String includePathRecalculated = ContextPath.getPartentPath(parentPath) + scalarNode.getValue(); node = new ScalarNode(scalarNode.getTag(), includePathRecalculated, node.getStartMark(), node.getEndMark(), scalarNode.getStyle()); } return includeResolver.resolve(node, resourceLoader, nodeNandler); } return node; }
if (node instanceof ScalarNode) { ScalarNode scalarNode = (ScalarNode) node; if (scalarNode.getTag().equals(Tag.FLOAT)) return Double.parseDouble(scalarNode.getValue()); else if (scalarNode.getTag().equals(Tag.INT)) return Integer.parseInt(scalarNode.getValue()); else if (scalarNode.getTag().equals(Tag.BOOL)) return Boolean.parseBoolean(scalarNode.getValue()); else return scalarNode.getValue(); Map<String, Object> nodeMap = new HashMap<String, Object>(); MappingNode mappingNode = (MappingNode) node; for (NodeTuple nodeTuple : mappingNode.getValue()) { if (nodeTuple.getKeyNode() instanceof ScalarNode) { String key = ((ScalarNode) nodeTuple.getKeyNode()).getValue(); nodeMap.put(key, yamlNodeToMap(nodeTuple.getValueNode()));
final MappingNode mappingNode = (MappingNode) yaml; json.writeStartObject(); for (NodeTuple tuple : mappingNode.getValue()) { if (tuple.getKeyNode() instanceof ScalarNode) { json.writeFieldName(((ScalarNode) tuple.getKeyNode()).getValue()); build(tuple.getValueNode(), json); } else if (yaml instanceof ScalarNode) { final ScalarNode scalarNode = (ScalarNode) yaml; final String className = scalarNode.getTag().getClassName(); if ("bool".equals(className)) { json.writeBoolean(Boolean.parseBoolean(scalarNode.getValue())); } else if ("int".equals(className)) { json.writeNumber(Long.parseLong(scalarNode.getValue()));
throws AraraException { Representer representer = new Representer(); representer.addClassTag(Rule.class, new Tag("!config")); Yaml yaml = new Yaml(new Constructor(Rule.class), representer); Rule rule = null; try {
private void processTypeMappingKeys(MappingNode mappingNode, ParsingContextExecution context, INodeParser<?> parser) { for (NodeTuple tuple : mappingNode.getValue()) { if (Tag.MERGE.equals(tuple.getKeyNode().getTag())) { MappingNode toMerge = (MappingNode) tuple.getValueNode(); processTypeMappingKeys(toMerge, context, parser); } else { // process a mapping map(tuple, (TypeNodeParser) parser, context); } } }
private String resolveParameterValueInclude(ScalarNode valueNode) { if (valueNode.getTag().equals(INCLUDE_TAG)) { Node resolved = includeResolver.resolve(valueNode, resourceLoader, nodeNandler); if (resolved.getNodeId() != scalar) { addError("Resource type and traits parameters must be scalars", valueNode); return ""; } valueNode = (ScalarNode) resolved; } return valueNode.getValue(); }
private boolean isNullValue(NodeTuple tuple) { return tuple.getValueNode().getTag().equals(Tag.NULL); }
public Constructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs) { if (theRoot == null) { throw new NullPointerException("Root type must be provided."); } this.yamlConstructors.put(null, new ConstructYamlObject()); if (!Object.class.equals(theRoot.getType())) { rootTag = new Tag(theRoot.getType()); } yamlClassConstructors.put(NodeId.scalar, new ConstructScalar()); yamlClassConstructors.put(NodeId.mapping, new ConstructMapping()); yamlClassConstructors.put(NodeId.sequence, new ConstructSequence()); addTypeDescription(theRoot); if (moreTDs != null) { for (TypeDescription td : moreTDs) { addTypeDescription(td); } } }
@Override protected NodeTuple representJavaBeanProperty( Object javaBean, Property property, Object propertyValue, Tag customTag) { NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); Node valueNode = nodeTuple.getValueNode(); if (Tag.NULL.equals(valueNode.getTag())) { return null; // skip 'null' values } if (valueNode instanceof CollectionNode) { if (Tag.SEQ.equals(valueNode.getTag())) { SequenceNode seq = (SequenceNode) valueNode; if (seq.getValue().isEmpty()) { return null; // skip empty lists } } if (Tag.MAP.equals(valueNode.getTag())) { MappingNode seq = (MappingNode) valueNode; if (seq.getValue().isEmpty()) { return null; // skip empty maps } } } Object name = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, property.getName()); return new NodeTuple(representData(name), valueNode); }
NodeTuple tagInclude(NodeTuple tuple) { if (Tag.NULL.equals(tuple.getValueNode().getTag())) { return tuple; } if (templateInclude != null) { tuple.getValueNode().setTag(templateInclude); } return tuple; } }
@Override protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) { List<NodeTuple> nodeValue = node.getValue(); for (NodeTuple tuple : nodeValue) { if (Tag.INT.equals(tuple.getKeyNode().getTag())) { tuple.getKeyNode().setTag(Tag.STR); } } super.constructMapping2ndStep(node, mapping); }