public static void main(final String[] args) throws IOException { final YAMLConfig cfg = YAML.config(); final Serializer s = new SerializerImpl(new EmitterImpl(System.out, cfg), new ResolverImpl(), cfg); s.open(); final Representer r = new RepresenterImpl(s, cfg); final Map test1 = new HashMap(); final List test1Val = new LinkedList(); test1Val.add("hello"); test1Val.add(Boolean.TRUE); test1Val.add(new Integer(31337)); test1.put("val1", test1Val); final List test2Val = new ArrayList(); test2Val.add("hello"); test2Val.add(Boolean.FALSE); test2Val.add(new Integer(31337)); test1.put("val2", test2Val); test1.put("afsdf", "hmm"); TestJavaBean bean1 = new TestJavaBean(); bean1.setName("Ola"); bean1.setSurName("Bini"); bean1.setAge(24); test1.put(new Integer(25), bean1); r.represent(test1); s.close(); }
public Node toYamlNode(Representer representer) throws IOException { final Map values = new HashMap(); final Method[] ems = data.getClass().getMethods(); for (int i = 0, j = ems.length; i < j; i++) { if (ems[i].getParameterTypes().length == 0) { final String name = ems[i].getName(); if (name.equals("getClass")) { continue; } String pname = null; if (name.startsWith("get")) { pname = "" + Character.toLowerCase(name.charAt(3)) + name.substring(4); } else if (name.startsWith("is")) { pname = "" + Character.toLowerCase(name.charAt(2)) + name.substring(3); } if (null != pname) { try { values.put(pname, ems[i].invoke(data, new Object[0])); } catch (final Exception exe) { values.put(pname, null); } } } } return representer.map(taguri(), values, false); }
public Node toYamlNode(final Representer representer) throws IOException { final Map entries = new HashMap(); for (final Iterator iter = data.iterator(); iter.hasNext(); ) { entries.put(iter.next(), null); } return representer.map(taguri(), entries, false); }
public Node toYamlNode(final Representer representer) throws IOException { final int l = java.lang.reflect.Array.getLength(data); final List lst = new ArrayList(l); for (int i = 0; i < l; i++) { lst.add(java.lang.reflect.Array.get(data, i)); } return representer.seq(taguri(), lst, false); }
public Node toYamlNode(Representer representer) throws IOException { String str = data.toString(); if (str.equals("Infinity")) { str = ".inf"; } else if (str.equals("-Infinity")) { str = "-.inf"; } else if (str.equals("NaN")) { str = ".nan"; } return representer.scalar(taguri(), ByteList.create(str), (char) 0); }
public Node toYamlNode(final Representer representer) throws IOException { final Calendar c = Calendar.getInstance(); c.setTime(data); String out = null; if (c.get(Calendar.MILLISECOND) != 0) { out = dateOutputUsec.format(data); } else { out = dateOutput.format(data); } out = out.substring(0, 23) + ":" + out.substring(23); return representer.scalar(taguri(), ByteList.create(out), (char) 0); }
public Node toYamlNode(Representer representer) throws IOException { return representer.map(taguri(), data, false); }
public Node toYamlNode(Representer representer) throws IOException { return representer.scalar(taguri(), (ByteList) data, (char) 0); }
public Node toYamlNode(Representer representer) throws IOException { return representer.scalar(taguri(), ByteList.create(data.toString()), (char) 0); }