@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);
}
项目:datatree-adapters
文件:YamlSnakeYaml.java
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);
}
return new ScalarNode(Tag.STR,txt,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(),options );
}
public Representer()
{
this.nullRepresenter = new RepresentNull(this);
this.representers.put(String.class,new RepresentJavaBean(this));
}
项目:datatree-adapters
文件:YamlSnakeYaml.java
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);
}
public void addRepresenter(Class<?> 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;
}
项目:yaml
文件:YamlNodeRepresenter.java
/**
* 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);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。