微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.yaml.snakeyaml.DumperOptions.FlowStyle的实例源码

项目:AndroidApktool    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,Iterable<?> sequence,Boolean flowStyle) {
    int size = 10;// default for ArrayList
    if (sequence instanceof List<?>) {
        size = ((List<?>) sequence).size();
    }
    List<Node> value = new ArrayList<Node>(size);
    SequenceNode node = new SequenceNode(tag,value,flowStyle);
    representedobjects.put(objectToRepresent,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:AndroidApktool    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,Map<?,?> mapping,Boolean flowStyle) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
    MappingNode node = new MappingNode(tag,node);
    boolean bestStyle = true;
    for (Map.Entry<?,?> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) {
            bestStyle = false;
        }
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:datatree-adapters    文件YamlSnakeYaml.java   
public YamlSnakeYaml() {

        // Representer
        ExtensibleRepresenter representer = new ExtensibleRepresenter();

        // Install Java / Apache Cassandra serializers
        addDefaultSerializers(representer);

        // Install MongoDB / BSON serializers
        tryToAddSerializers("io.datatree.dom.adapters.YamlSnakeYamlBsonSerializers",representer);

        // Create flow-style YAML mapper
        DumperOptions optionsnormal = new DumperOptions();
        optionsnormal.setDefaultFlowStyle(FlowStyle.FLOW);
        mapper = new Yaml(representer,optionsnormal);

        // Create "pretty" YAML mapper
        DumperOptions optionspretty = new DumperOptions();
        optionspretty.setDefaultFlowStyle(FlowStyle.BLOCK);
        prettyMapper = new Yaml(representer,optionspretty);
    }
项目:5zig-TIMV-Plugin    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:5zig-TIMV-Plugin    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:waggle-dance    文件YamlFactory.java   
public static Yaml newYaml() {
  PropertyUtils propertyUtils = new AdvancedPropertyUtils();
  propertyUtils.setSkipMissingProperties(true);

  Constructor constructor = new Constructor(Federations.class);
  TypeDescription federationDescription = new TypeDescription(Federations.class);
  federationDescription.putListPropertyType("federatedmetastores",Federatedmetastore.class);
  constructor.addTypeDescription(federationDescription);
  constructor.setPropertyUtils(propertyUtils);

  Representer representer = new AdvancedRepresenter();
  representer.setPropertyUtils(new FieldOrderPropertyUtils());
  representer.addclasstag(Federations.class,Tag.MAP);
  representer.addclasstag(Abstractmetastore.class,Tag.MAP);
  representer.addclasstag(WaggleDanceConfiguration.class,Tag.MAP);
  representer.addclasstag(YamlStorageConfiguration.class,Tag.MAP);
  representer.addclasstag(GraphiteConfiguration.class,Tag.MAP);

  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setIndent(2);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);

  return new Yaml(constructor,representer,dumperOptions);
}
项目:snake-yaml    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:snake-yaml    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:snake-yaml    文件JodaTimeFlowStylesTest.java   
/**
 * !!timestamp must be used,without it the implicit tag will be ignored
 * because 'date' is the JavaBean property.
 * 
 * Since the timestamp contains ':' character it cannot use plain scalar
 * style in the FLOW mapping style. Emitter suggests single quoted scalar
 * style and that is why the explicit '!!timestamp' is present in the YAML
 * document.
 * 
 * @see <a href="http://code.google.com/p/snakeyaml/issues/detail?id=128"></a>
 * 
 */
public void testLoadBeanWithAutoFlow() {
    MyBean bean = new MyBean();
    bean.setId("id123");
    DateTime etalon = new DateTime(timestamp,DateTimeZone.UTC);
    bean.setDate(etalon);
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.AUTO);
    Yaml dumper = new Yaml(new JodaTimeRepresenter(),options);
    String doc = dumper.dump(bean);
    // System.out.println(doc);
    assertEquals(
            "!!examples.jodatime.MyBean {date: !!timestamp '2001-09-09T01:46:40Z',id: id123}\n",doc);
    Yaml loader = new Yaml(new JodaTimeImplicitContructor());
    MyBean parsed = (MyBean) loader.load(doc);
    assertEquals(etalon,parsed.getDate());
}
项目:snake-yaml    文件JavaBeanTimeStampTest.java   
public void testLoadDefaultJavasqlTimestamp() {
    JavaBeanWithsqlTimestamp javaBeanToDump = new JavaBeanWithsqlTimestamp();
    Timestamp stamp = new Timestamp(1000000000000L);
    javaBeanToDump.setTimestamp(stamp);
    Date date = new Date(1001376000000L);
    javaBeanToDump.setDate(date);
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    String dumpStr = yaml.dump(javaBeanToDump);
    assertEquals(
            "!!org.yaml.snakeyaml.JavaBeanWithsqlTimestamp\ndate: 2001-09-25T00:00:00Z\ntimestamp: 2001-09-09T01:46:40Z\n",dumpStr);
    Yaml loader = new Yaml();
    JavaBeanWithsqlTimestamp javaBeantoload = loader.loadAs(dumpStr,JavaBeanWithsqlTimestamp.class);
    assertEquals(stamp,javaBeantoload.getTimestamp());
    assertEquals(date,javaBeantoload.getDate());
}
项目:snake-yaml    文件SingleQuoteTest.java   
private void checkQuotes(boolean isBlock,String expectation) {
    DumperOptions options = new DumperOptions();
    options.setIndent(4);
    if (isBlock) {
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
    }
    Representer representer = new Representer();

    Yaml yaml = new Yaml(new SafeConstructor(),options);

    LinkedHashMap<String,Object> lvl1 = new LinkedHashMap<String,Object>();
    lvl1.put("steak:cow","11");
    LinkedHashMap<String,Object> root = new LinkedHashMap<String,Object>();
    root.put("cows",lvl1);
    String output = yaml.dump(root);
    assertEquals(expectation + "\n",output);

    // parse the value back
    @SuppressWarnings("unchecked")
    Map<String,Object> cows = (Map<String,Object>) yaml.load(output);
    @SuppressWarnings("unchecked")
    Map<String,String> cow = (Map<String,String>) cows.get("cows");
    assertEquals("11",cow.get("steak:cow"));
}
项目:snake-yaml    文件ImplicitTagsTest.java   
public void testnoroottag() {
    CarWithWheel car1 = new CarWithWheel();
    car1.setPlate("12-XP-F4");
    Wheel wheel = new Wheel();
    wheel.setId(2);
    car1.setWheel(wheel);
    Map<String,Integer> map = new HashMap<String,Integer>();
    map.put("id",3);
    car1.setMap(map);
    car1.setYear("2008");
    String carYaml1 = new Yaml().dumpAs(car1,Tag.MAP,FlowStyle.AUTO);
    assertEquals(Util.getLocalResource("constructor/car-without-root-tag.yaml"),carYaml1);
    //
    Constructor contructor = new Constructor(CarWithWheel.class);
    CarWithWheel car2 = (CarWithWheel) new Yaml(contructor).load(carYaml1);
    String carYaml2 = new Yaml().dumpAs(car2,FlowStyle.AUTO);
    assertEquals(carYaml1,carYaml2);
}
项目:snake-yaml    文件EmitterTest.java   
public void testSplitLineExpectFirstFlowSequenceItem() {

        DumperOptions options = new DumperOptions();
        options.setDefaultScalarstyle(DumperOptions.Scalarstyle.DOUBLE_QUOTED);
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
        options.setWidth(8);
        Yaml yaml;
        String output;
        Map<String,Object> map = new TreeMap<String,Object>();
        map.put("12345",Arrays.asList("1111111111"));

        // Split lines enabled (default)
        yaml = new Yaml(options);
        output = yaml.dump(map);
        assertEquals("{\"12345\": [\n    \"1111111111\"]}\n",output);

        // Split lines disabled
        options.setSplitLines(false);
        assertFalse(options.getSplitLines());
        yaml = new Yaml(options);
        output = yaml.dump(map);
        assertEquals("{\"12345\": [\"1111111111\"]}\n",output);
    }
项目:snake-yaml    文件EmitterTest.java   
public void testSplitLineExpectFlowSequenceItem() {

        DumperOptions options = new DumperOptions();
        options.setDefaultScalarstyle(DumperOptions.Scalarstyle.DOUBLE_QUOTED);
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);
        options.setWidth(8);
        Yaml yaml;
        String output;

        // Split lines enabled (default)
        yaml = new Yaml(options);
        output = yaml.dump(Arrays.asList("1111111111","2222222222"));
        assertEquals("[\"1111111111\",\n  \"2222222222\"]\n",output);
        output = yaml.dump(Arrays.asList("1","2"));
        assertEquals("[\"1\",\"2\"]\n",output);

        // Split lines disabled
        options.setSplitLines(false);
        assertFalse(options.getSplitLines());
        yaml = new Yaml(options);
        output = yaml.dump(Arrays.asList("1111111111",\"2222222222\"]\n",output);
    }
项目:snake-yaml    文件EmitterMultiLineTest.java   
public void testWriteMultiLineList() {
    String one = "first\nsecond\nthird";
    String two = "one\ntwo\nthree\n";
    byte[] binary = { 8,14,15,10,126,32,65,65 };
    List<Object> list = new ArrayList<Object>(2);
    list.add(one);
    list.add(two);
    list.add(binary);
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(list);
    // System.out.println(output);
    String etalon = "- |-\n  first\n  second\n  third\n- |\n  one\n  two\n  three\n- !!binary |-\n  CA4PCn4gQUFB\n";
    assertEquals(etalon,output);
    @SuppressWarnings("unchecked")
    List<Object> parsed = (List<Object>) yaml.load(etalon);
    assertEquals(3,parsed.size());
    assertEquals(one,parsed.get(0));
    assertEquals(two,parsed.get(1));
    assertEquals(new String(binary),new String((byte[]) parsed.get(2)));
}
项目:aml    文件GenericWriter.java   
protected final String dumpMap(LinkedHashMap<Object,Object> toStore,String header) {
    DumperOptions dumperOptions = new DumperOptions();
    toStore = cleanMap(toStore);
    dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
    dumperOptions.setAllowUnicode(true);
    Yaml rl = new Yaml(dumperOptions);
    StringWriter stringWriter = new StringWriter();
    BufferedWriter ws = new BufferedWriter(stringWriter);
    try {
        ws.write(header);
        ws.newLine();
        rl.dump(toStore,ws);
        return stringWriter.toString().replaceAll(NovalUE,"");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:SubServers-2    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:SubServers-2    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:snakeyaml    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!(nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:snakeyaml    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:snakeyaml    文件JodaTimeFlowStylesTest.java   
/**
 * !!timestamp must be used,without it the implicit tag will be ignored
 * because 'date' is the JavaBean property.
 * 
 * Since the timestamp contains ':' character it cannot use plain scalar
 * style in the FLOW mapping style. Emitter suggests single quoted scalar
 * style and that is why the explicit '!!timestamp' is present in the YAML
 * document.
 * 
 * @see http://code.google.com/p/snakeyaml/issues/detail?id=128
 * 
 */
public void testLoadBeanWithAutoFlow() {
    MyBean bean = new MyBean();
    bean.setId("id123");
    DateTime etalon = new DateTime(timestamp,parsed.getDate());
}
项目:snakeyaml    文件JavaBeanTimeStampTest.java   
public void testLoadDefaultJavasqlTimestamp() {
    JavaBeanWithsqlTimestamp javaBeanToDump = new JavaBeanWithsqlTimestamp();
    Timestamp stamp = new Timestamp(1000000000000L);
    javaBeanToDump.setTimestamp(stamp);
    Date date = new Date(1001376000000L);
    javaBeanToDump.setDate(date);
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    String dumpStr = yaml.dump(javaBeanToDump);
    assertEquals(
            "!!org.yaml.snakeyaml.JavaBeanWithsqlTimestamp\ndate: 2001-09-25T00:00:00Z\ntimestamp: 2001-09-09T01:46:40Z\n",javaBeantoload.getDate());
}
项目:snakeyaml    文件SingleQuoteTest.java   
private void checkQuotes(boolean isBlock,cow.get("steak:cow"));
}
项目:snakeyaml    文件ImplicitTagsTest.java   
public void testnoroottag() {
    CarWithWheel car1 = new CarWithWheel();
    car1.setPlate("12-XP-F4");
    Wheel wheel = new Wheel();
    wheel.setId(2);
    car1.setWheel(wheel);
    Map<String,carYaml2);
}
项目:snakeyaml    文件EmitterMultiLineTest.java   
public void testWriteMultiLineList() {
    String one = "first\nsecond\nthird";
    String two = "one\ntwo\nthree\n";
    byte[] binary = { 8,new String((byte[]) parsed.get(2)));
}
项目:TestTheTeacher    文件BaseRepresenter.java   
protected Node representSequence(Tag tag,Iterable<? extends Object> sequence,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!((nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:TestTheTeacher    文件BaseRepresenter.java   
protected Node representMapping(Tag tag,Map<? extends Object,Object> mapping,node);
    boolean bestStyle = true;
    for (Map.Entry<? extends Object,Object> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!((nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null))) {
            bestStyle = false;
        }
        if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:org.openntf.domino    文件BaseRepresenter.java   
protected Node representSequence(final Tag tag,final Iterable<?> sequence,final Boolean flowStyle) {
    int size = 10;// default for ArrayList
    if (sequence instanceof List<?>) {
        size = ((List<?>) sequence).size();
    }
    List<Node> value = new ArrayList<Node>(size);
    SequenceNode node = new SequenceNode(tag,node);
    boolean bestStyle = true;
    for (Object item : sequence) {
        Node nodeItem = representData(item);
        if (!((nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(nodeItem);
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:org.openntf.domino    文件BaseRepresenter.java   
protected Node representMapping(final Tag tag,final Map<?,final Boolean flowStyle) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
    MappingNode node = new MappingNode(tag,?> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!((nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null))) {
            bestStyle = false;
        }
        if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey,nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
项目:yaml    文件YamlNodeRepresenter.java   
/**
 * Create a {@link MappingNode} from the specified entries and tag.
 *
 * @param tag     the tag
 * @param mapping the entries
 *
 * @return the mapping node
 */
private MappingNode delegate(Tag tag,Iterable<Entry<YamlNode,YamlNode>> mapping) {
    List<NodeTuple> value = new LinkedList<>();
    MappingNode node = new MappingNode(tag,null);
    representedobjects.put(objectToRepresent,?> entry : mapping) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        bestStyle = bestStyle(nodeKey,bestStyle);
        bestStyle = bestStyle(nodeValue,bestStyle);
        value.add(new NodeTuple(nodeKey,nodeValue));
    }

    if (getDefaultFlowStyle() != FlowStyle.AUTO) {
        node.setFlowStyle(getDefaultFlowStyle().getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:t4f-data    文件JodaTimeFlowStylesTest.java   
/**
 * !!timestamp must be used,options);
    String doc = dumper.dump(bean);
    // System.out.println(doc);
    assertEquals("!!examples.jodatime.MyBean {date: !!timestamp '2001-09-09T01:46:40Z',parsed.getDate());
}
项目:marathonv5    文件ObjectMapConfiguration.java   
public void save() throws IOException {
    FileWriter writer = new FileWriter(getConfigFile());
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.AUTO);
    options.setIndent(4);
    Representer representer = new Representer();
    representer.getPropertyUtils().setBeanAccess(BeanAccess.DEFAULT);
    new Yaml(options).dump(this,writer);
}
项目:AndroidApktool    文件Representer.java   
/**
 * Tag logic:<br/>
 * - explicit root tag is set in serializer <br/>
 * - if there is a predefined class tag it is used<br/>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 * 
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties,Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classtags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag,null);
    representedobjects.put(javaBean,node);
    boolean bestStyle = true;
    for (Property property : properties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null : classtags.get(memberValue
                .getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean,property,memberValue,customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:5zig-TIMV-Plugin    文件Representer.java   
/**
 * Tag logic:
 * - explicit root tag is set in serializer
 * - if there is a predefined class tag it is used
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:flow-platform    文件NodeUtil.java   
@Override
protected MappingNode representJavaBean(Set<Property> properties,Object javaBean) {
    List<NodeTuple> value = new ArrayList<>(properties.size());
    Tag tag;
    Tag customTag = classtags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    MappingNode node = new MappingNode(tag,node);
    boolean bestStyle = true;

    List<Property> orderProperties = new ArrayList<>(properties);
    orderProperties.sort(sorter);

    for (Property property : orderProperties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null
            : classtags.get(memberValue.getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean,customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        org.yaml.snakeyaml.nodes.Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:snake-yaml    文件Representer.java   
/**
 * Tag logic:<br>
 * - explicit root tag is set in serializer <br>
 * - if there is a predefined class tag it is used<br>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 *
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties,customPropertyTag);
        if (tuple == null) {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
项目:snake-yaml    文件HumanTest.java   
public void testNoChildrenPretty() {
    Human father = new Human();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    Human mother = new Human();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    DumperOptions options = new DumperOptions();
    options.setPrettyFlow(true);
    options.setDefaultFlowStyle(FlowStyle.FLOW);
    Yaml yaml = new Yaml(options);
    String output = yaml.dump(father);
    String etalon = Util.getLocalResource("recursive/no-children-1-pretty.yaml");
    assertEquals(etalon,output);
    //
    Human father2 = (Human) yaml.load(output);
    assertNotNull(father2);
    assertEquals("Father",father2.getName());
    assertEquals("Mother",father2.getPartner().getName());
    assertEquals("Father",father2.getBankAccountOwner().getName());
    assertSame(father2,father2.getBankAccountOwner());
}
项目:snake-yaml    文件DumpSetAsSequenceExampleTest.java   
public void testDumpBlock() {
    DumperOptions options = new DumperOptions();
    options.setAllowReadOnlyProperties(true);
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(new SetRepresenter(),options);
    String output = yaml.dump(createBlog());
    // System.out.println(output);
    assertEquals(Util.getLocalResource("issues/issue73-dump8.txt"),output);
    //
    check(output);
}
项目:snake-yaml    文件ArrayInGenericCollectionTest.java   
public void testNoTags() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    B data = createB();
    String dump = yaml2dump.dumpAs(data,FlowStyle.AUTO);
    // System.out.println(dump);
    assertEquals("Meta:\n- [whatever]\n- [something,something else]\n",dump);
    //
    Constructor constr = new Constructor(B.class);
    Yaml yaml2load = new Yaml(constr);
    yaml2load.setBeanAccess(BeanAccess.FIELD);
    B loaded = (B) yaml2load.load(dump);

    Assert.assertArrayEquals(data.Meta.toArray(),loaded.Meta.toArray());
}
项目:snake-yaml    文件DumpTest.java   
public void testDumperNullStyle2() {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.BLOCK);
    Yaml yaml = new Yaml(options);
    Bean124 bean = new Bean124();
    String output1 = yaml.dumpAs(bean,new Tag("!!foo2.bar2"),null);
    assertEquals("!!foo2.bar2\na: aaa\nnumbers:\n- 1\n- 2\n- 3\n",output1);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。