@Override protected Yaml initialValue() { Representer representer = new Representer() { { representers.put(Configuration.class, new Represent() { @Override public Node representData(Object data) { return represent(((Configuration) data).self); } }); } }; DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); return new Yaml(new Constructor(), representer, options); }
public static final <T> void addSerializer(ExtensibleRepresenter representer, Class<T> type, Function<T, String> function) { representer.addRepresenter(type, new Represent() { @SuppressWarnings("unchecked") @Override public Node representData(Object data) { String txt = function.apply((T) data); if (txt == null) { return new ScalarNode(Tag.NULL, "null", null, null, null); } return new ScalarNode(Tag.STR, txt, null, null, null); } }); }
public Representer() { this.nullRepresenter = new RepresentNull(this); this.representers.put(String.class, new RepresentString(this)); this.representers.put(Boolean.class, new RepresentBoolean(this)); this.representers.put(Character.class, new RepresentString(this)); this.representers.put(UUID.class, new RepresentUuid(this)); this.representers.put(byte[].class, new RepresentByteArray(this)); Represent primitiveArray = new RepresentPrimitiveArray(this); this.representers.put(short[].class, primitiveArray); this.representers.put(int[].class, primitiveArray); this.representers.put(long[].class, primitiveArray); this.representers.put(float[].class, primitiveArray); this.representers.put(double[].class, primitiveArray); this.representers.put(char[].class, primitiveArray); this.representers.put(boolean[].class, primitiveArray); this.classTags = new HashMap<>(10); this.representers.put(null, new RepresentJavaBean(this)); }
@Override protected Yaml initialValue() { Representer representer = new Representer() { { representers.put( Configuration.class, new Represent() { @Override public Node representData(Object data) { return represent( ( (Configuration) data ).self ); } } ); } }; DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK ); return new Yaml( new Constructor(), representer, options ); }
public void addRepresenter(Class<?> type, Represent represent) { representers.put(type, represent); }
public void addRepresenter(Class<?> type, Represent represent) { this.representers.put(type, represent); LinkedHashMap<Class<?>, Represent> multiRepresenters = (LinkedHashMap<Class<?>, Represent>) this.multiRepresenters; multiRepresenters.put(type, represent); }
/** * Returns representers map of this yaml representer instance. * * @return representers map of this yaml representer instance. */ public Map<Class<?>, Represent> getRepresenters() { return this.representers; }
/** * Returns null representer of this yaml representer instance. * * @return null representer of this yaml representer instance. */ public Represent getNullRepresenter() { return this.nullRepresenter; }
/** * Set null representer of this yaml representer instance. * * @param nullRepresenter new null representer. */ public void setNullRepresenter(final Represent nullRepresenter) { this.nullRepresenter = nullRepresenter; }
/** * Returns representers map of this yaml representer instance. * * @return representers map of this yaml representer instance. */ public Map<Class<?>, Represent> getMultiRepresenters() { return this.multiRepresenters; }
/** * Register the {@link Represent} in {@link #representers} and * {@link #multiRepresenters}. * * @param type the type to register for * @param represent the represent */ private void register(Class<? extends YamlNode> type, Represent represent) { this.representers.put(type, represent); this.multiRepresenters.put(type, represent); }