protected Class<?> getClassForNode(Node node) { Class<? extends Object> classForTag = typeTags.get(node.getTag()); if (classForTag == null) { String name = node.getTag().getClassName(); Class<?> cl; try { cl = getClassForName(name); } catch (ClassNotFoundException e) { throw new YAMLException("Class not found: " + name); } typeTags.put(node.getTag(), cl); return cl; } else { return classForTag; } }
protected Class<?> getClassForNode(Node node) { Class<? extends Object> classForTag = typeTags.get(node.getTag()); if (classForTag == null) { String name = node.getTag().getClassName(); Class<?> cl; try { cl = getClassForName(name); } catch (ClassNotFoundException e) { throw new YAMLException("Class not found: " + name); } typeTags.put(node.getTag(), cl); return cl; } else { return classForTag; } }
protected Class<?> getClassForNode(Node node) { Class<? extends Object> classForTag = typeTags.get(node.getTag()); if (classForTag == null) { String name = node.getTag().getClassName(); Class<?> cl; try { cl = getClassForName(name); } catch (ClassNotFoundException e) { throw new YAMLException("Class not found: " + name); } typeTags.put(node.getTag(), cl); return cl; } else { return classForTag; } }
protected Class<?> getClassForNode(Node node) { Class<? extends Object> classForTag = typeTags.get(node.getTag()); if (classForTag == null) { String name = node.getTag().getClassName(); Class<?> cl; try { cl = getClassForName(name); } catch (ClassNotFoundException e) { throw new YAMLException("Class not found: " + name); } typeTags.put(node.getTag(), cl); return cl; } else { return classForTag; } }
/** * Resolves the type of a node after the tag gets re-resolved. * * @param node * @throws ClassNotFoundException */ private void resolveType(Node node) throws ClassNotFoundException { String typeName = node.getTag().getClassName(); if(typeName.equals("int")) { node.setType(Integer.TYPE); } else if(typeName.equals("float")) { node.setType(Float.TYPE); } else if(typeName.equals("double")) { node.setType(Double.TYPE); } else if(typeName.equals("bool")) { node.setType(Boolean.TYPE); } else if(typeName.equals("date")) { node.setType(Date.class); } else if(typeName.equals("seq")) { node.setType(List.class); } else if(typeName.equals("str")) { node.setType(String.class); } else if(typeName.equals("map")) { node.setType(Map.class); } else { node.setType(getClassForName(node.getTag().getClassName())); } } }
/** * Overridden to fetch constructor even if tag is not mapped. */ @Override protected Construct getConstructor(Node node) { Construct construct = super.getConstructor(node); logger.trace("getting constructor for node {} Tag {} = {}", new Object[] {node, node.getTag(), construct}); if(construct instanceof ConstructYamlObject && !tagsDefined.contains(node.getTag())) { try { node.getTag().getClassName(); } catch(YAMLException e) { node.setUseClassConstructor(true); String value = null; if(node.getNodeId() == NodeId.scalar) { value = ((ScalarNode)node).getValue(); } node.setTag(resolver.resolve(node.getNodeId(), value, true)); construct = super.getConstructor(node); try { resolveType(node); } catch (ClassNotFoundException e1) { logger.debug("Could not find class.", e1); } } } logger.trace("returning constructor for node {} type {} Tag {} = {}", new Object[] {node, node.getType(), node.getTag(), construct}); return construct; }
if (target == Object.class && node.getTag().startsWith(Tag.PREFIX) && !noClass.contains(node.getTag())) { try { target = Class.forName(node.getTag().getClassName()); } catch (ClassNotFoundException ignored) {
} 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()));