/** * Produce the corresponding representation tree for a given Object. * * @see <a href="http://yaml.org/spec/1.1/#id859333">Figure 3.1. Processing * Overview</a> * @param data * instance to build the representation tree for * @return representation tree */ public Node represent(Object data) { return representer.represent(data); }
/** * Create Yaml instance. It is safe to create a few instances and use them * in different Threads. * * @param constructor * BaseConstructor to construct incoming documents */ public Yaml(BaseConstructor constructor) { this(constructor, new Representer()); }
public Node representData(Object data) { return representScalar(Tag.NULL, "null"); } }
public SafeRepresenter() { this.nullRepresenter = new RepresentNull(); this.representers.put(String.class, new RepresentString()); this.representers.put(Boolean.class, new RepresentBoolean()); this.representers.put(Character.class, new RepresentString()); this.representers.put(UUID.class, new RepresentUuid()); this.representers.put(byte[].class, new RepresentByteArray()); Represent primitiveArray = new RepresentPrimitiveArray(); representers.put(short[].class, primitiveArray); representers.put(int[].class, primitiveArray); representers.put(long[].class, primitiveArray); representers.put(float[].class, primitiveArray); representers.put(double[].class, primitiveArray); representers.put(char[].class, primitiveArray); representers.put(boolean[].class, primitiveArray); this.multiRepresenters.put(Number.class, new RepresentNumber()); this.multiRepresenters.put(List.class, new RepresentList()); this.multiRepresenters.put(Map.class, new RepresentMap()); this.multiRepresenters.put(Set.class, new RepresentSet()); this.multiRepresenters.put(Iterator.class, new RepresentIterator()); this.multiRepresenters.put(new Object[0].getClass(), new RepresentArray()); this.multiRepresenters.put(Date.class, new RepresentDate()); this.multiRepresenters.put(Enum.class, new RepresentEnum()); this.multiRepresenters.put(Calendar.class, new RepresentDate()); classTags = new HashMap<Class<? extends Object>, Tag>(); }
private static DumperOptions initDumperOptions(Representer representer) { DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(representer.getDefaultFlowStyle()); dumperOptions.setDefaultScalarStyle(representer.getDefaultScalarStyle()); dumperOptions.setAllowReadOnlyProperties(representer.getPropertyUtils().isAllowReadOnlyProperties()); dumperOptions.setTimeZone(representer.getTimeZone()); return dumperOptions; }
public Node representData(Object data) { return representJavaBean(getProperties(data.getClass()), data); } }
@SuppressWarnings("unchecked") public Node representData(Object data) { Iterator<Object> iter = (Iterator<Object>) data; return representSequence(getTag(data.getClass(), Tag.SEQ), new IteratorWrapper(iter), DumperOptions.FlowStyle.AUTO); } }
@SuppressWarnings("unchecked") public Node representData(Object data) { return representSequence(getTag(data.getClass(), Tag.SEQ), (List<Object>) data, DumperOptions.FlowStyle.AUTO); } }
@SuppressWarnings("unchecked") public Node representData(Object data) { return representMapping(getTag(data.getClass(), Tag.MAP), (Map<Object, Object>) data, DumperOptions.FlowStyle.AUTO); } }
protected Node representScalar(Tag tag, String value) { return representScalar(tag, value, null); }
public Node represent(Object data) { Node node = representData(data); representedObjects.clear(); objectToRepresent = null; return node; }
public Node representData(Object data) { Object[] array = (Object[]) data; List<Object> list = Arrays.asList(array); return representSequence(Tag.SEQ, list, DumperOptions.FlowStyle.AUTO); } }
public Representer() { this.representers.put(null, new RepresentJavaBean()); }
public void addTypeDescription(TypeDescription td) { constructor.addTypeDescription(td); representer.addTypeDescription(td); } }
@Override public void setPropertyUtils(PropertyUtils propertyUtils) { super.setPropertyUtils(propertyUtils); Collection<TypeDescription> tds = typeDefinitions.values(); for (TypeDescription typeDescription : tds) { typeDescription.setPropertyUtils(propertyUtils); } }
@Override public Node representData(Object data) { return super.representData(YamlStringEscapeUtils.escapeString(data.toString())); } }
/** * Create Yaml instance. * * @param dumperOptions * DumperOptions to configure outgoing objects */ public Yaml(DumperOptions dumperOptions) { this(new Constructor(), new Representer(), dumperOptions); }
public Node representData(Object data) { String value; if (Boolean.TRUE.equals(data)) { value = "true"; } else { value = "false"; } return representScalar(Tag.BOOL, value); } }
/** * Create Yaml instance. * * @param loadingConfig * LoadingConfig to control load behavior */ public Yaml(LoaderOptions loadingConfig) { this(new Constructor(), new Representer(), new DumperOptions(), loadingConfig); }
public Node representData(Object data) { char[] binary = Base64Coder.encode((byte[]) data); return representScalar(Tag.BINARY, String.valueOf(binary), DumperOptions.ScalarStyle.LITERAL); } }