/** * Create Yaml instance. It is safe to create a few instances and use them * in different Threads. * * @param constructor * BaseConstructor to construct incoming documents * @param representer * Representer to emit outgoing objects * @param dumperOptions * DumperOptions to configure outgoing objects * @param resolver * Resolver to detect implicit type */ public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, Resolver resolver) { if (!constructor.isExplicitPropertyUtils()) { constructor.setPropertyUtils(representer.getPropertyUtils()); } else if (!representer.isExplicitPropertyUtils()) { representer.setPropertyUtils(constructor.getPropertyUtils()); } this.constructor = constructor; representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle()); representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle()); representer.getPropertyUtils().setAllowReadOnlyProperties( dumperOptions.isAllowReadOnlyProperties()); representer.setTimeZone(dumperOptions.getTimeZone()); this.representer = representer; this.dumperOptions = dumperOptions; this.resolver = resolver; this.name = "Yaml:" + System.identityHashCode(this); }
/** * Create Yaml instance. It is safe to create a few instances and use them * in different Threads. * * @param constructor * BaseConstructor to construct incoming documents * @param representer * Representer to emit outgoing objects * @param dumperOptions * DumperOptions to configure outgoing objects * @param loadingConfig * LoadingConfig to control load behavior * @param resolver * Resolver to detect implicit type */ public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions, LoaderOptions loadingConfig, Resolver resolver) { if (!constructor.isExplicitPropertyUtils()) { constructor.setPropertyUtils(representer.getPropertyUtils()); } else if (!representer.isExplicitPropertyUtils()) { representer.setPropertyUtils(constructor.getPropertyUtils()); } this.constructor = constructor; this.constructor.setAllowDuplicateKeys(loadingConfig.isAllowDuplicateKeys()); if (dumperOptions.getIndent() <= dumperOptions.getIndicatorIndent()) { throw new YAMLException("Indicator indent must be smaller then indent."); } representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle()); representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle()); representer.getPropertyUtils() .setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties()); representer.setTimeZone(dumperOptions.getTimeZone()); this.representer = representer; this.dumperOptions = dumperOptions; this.loadingConfig = loadingConfig; this.resolver = resolver; this.name = "Yaml:" + System.identityHashCode(this); }
/** * Create Yaml instance. It is safe to create a few instances and use them * in different Threads. * * @param serialization * serialization instance. * @param constructor * BaseConstructor to construct incoming documents * @param representer * Representer to emit outgoing objects * @param dumperOptions * DumperOptions to configure outgoing objects * @param resolver * Resolver to detect implicit type */ public Yaml(Serialization serialization, YamlConstructor constructor, Representer representer, DumperOptions dumperOptions, Resolver resolver) { representer.initMultiRepresenters(); this.serialization = serialization; if (! constructor.isExplicitPropertyUtils()) { constructor.setPropertyUtils(representer.getPropertyUtils()); } else if (! representer.isExplicitPropertyUtils()) { representer.setPropertyUtils(constructor.getPropertyUtils()); } this.constructor = constructor; representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle()); representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle()); representer.getPropertyUtils().setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties()); representer.setTimeZone(dumperOptions.getTimeZone()); this.representer = representer; this.dumperOptions = dumperOptions; this.resolver = resolver; this.name = "Yaml:" + DioriteThreadUtils.getFullThreadName(Thread.currentThread()); }
public Yaml createYamlReader() { return new Yaml(new Constructor(), new Representer(), new DumperOptions(), new Resolver() { @Override protected void addImplicitResolvers() { // Intentionally left TIMESTAMP as string to let DBUnit deal with the conversion addImplicitResolver(Tag.BOOL, BOOL, "yYnNtTfFoO"); addImplicitResolver(Tag.INT, INT, "-+0123456789"); addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789."); addImplicitResolver(Tag.MERGE, MERGE, "<"); addImplicitResolver(Tag.NULL, NULL, "~nN\0"); addImplicitResolver(Tag.NULL, EMPTY, null); addImplicitResolver(Tag.VALUE, VALUE, "="); addImplicitResolver(Tag.YAML, YAML, "!&*"); } }); }
private static Yaml newYaml() { return new Yaml(new Constructor(), new Representer(), new DumperOptions(), new Resolver() { @Override public Tag resolve(NodeId kind, String value, boolean implicit) { if (value != null) { if (value.equalsIgnoreCase("on") || value.equalsIgnoreCase("off") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("no")) { return Tag.STR; } } return super.resolve(kind, value, implicit); } }); }
public Serializer(Serialization serialization, Emitable emitter, Resolver resolver, DumperOptions opts, @Nullable Tag rootTag) { this.serialization = serialization; this.emitter = EmitableWrapper.wrap(emitter); this.resolver = resolver; this.explicitStart = opts.isExplicitStart(); this.explicitEnd = opts.isExplicitEnd(); if (opts.getVersion() != null) { this.useVersion = opts.getVersion(); } this.useTags = opts.getTags(); this.serializedNodes = new HashSet<>(50); this.anchors = new HashMap<>(10); this.anchorGenerator = opts.getAnchorGenerator(); this.closed = null; this.explicitRoot = rootTag; }
private List<Node> compose_all(InputStream file) { Composer composer = new Composer(new ParserImpl(new StreamReader(new UnicodeReader(file))), new Resolver()); List<Node> documents = new ArrayList<Node>(); while (composer.checkNode()) { documents.add(composer.getNode()); } return documents; }
/** * Create Yaml instance. It is safe to create a few instances and use them in different Threads. * * @param constructor * BaseConstructor to construct incoming documents * @param representer * Representer to emit outgoing objects * @param dumperOptions * DumperOptions to configure outgoing objects * @param resolver * Resolver to detect implicit type */ public Yaml(final BaseConstructor constructor, final Representer representer, final DumperOptions dumperOptions, final Resolver resolver) { if (!constructor.isExplicitPropertyUtils()) { constructor.setPropertyUtils(representer.getPropertyUtils()); } else if (!representer.isExplicitPropertyUtils()) { representer.setPropertyUtils(constructor.getPropertyUtils()); } this.constructor = constructor; representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle()); representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle()); representer.getPropertyUtils().setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties()); representer.setTimeZone(dumperOptions.getTimeZone()); this.representer = representer; this.dumperOptions = dumperOptions; this.resolver = resolver; this.name = "Yaml:" + System.identityHashCode(this); }
public Serializer(Emitable emitter, Resolver resolver, DumperOptions opts, Tag rootTag) { this.emitter = emitter; this.resolver = resolver; this.explicitStart = opts.isExplicitStart(); this.explicitEnd = opts.isExplicitEnd(); if (opts.getVersion() != null) { this.useVersion = opts.getVersion(); } this.useTags = opts.getTags(); this.serializedNodes = new HashSet<Node>(); this.anchors = new HashMap<Node, String>(); this.anchorGenerator = opts.getAnchorGenerator(); this.closed = null; this.explicitRoot = rootTag; }
public Serializer(Serialization serialization, Emitable emitter, Resolver resolver, DumperOptions opts, @Nullable Tag rootTag) { this.serialization = serialization; this.emitter = EmitableWrapper.wrap(emitter); this.resolver = resolver; this.explicitStart = opts.isExplicitStart(); this.explicitEnd = opts.isExplicitEnd(); if (opts.getVersion() != null) { this.useVersion = opts.getVersion(); } this.useTags = opts.getTags(); this.serializedNodes = new HashSet<>(50); this.anchors = new HashMap<>(10); // compatibility if (! hasAnchorGenerator) { this.anchorGenerator = new NumberAnchorGenerator(); } else { Object anchorGenerator = opts.getAnchorGenerator(); this.anchorGenerator = ((org.yaml.snakeyaml.serializer.AnchorGenerator) anchorGenerator)::nextAnchor; } this.closed = null; this.explicitRoot = rootTag; }
public void testFragment() { String document = "foo: blargle\n" + "developer: { name: \"Bjarne Stroustrup\", language: \"C++\"}\n" + "gee: [ \"whiz\", \"bang\"]\n";// StreamReader reader = new StreamReader(document); Composer composer = new FragmentComposer(new ParserImpl(reader), new Resolver(), "developer"); Constructor constructor = new Constructor(); constructor.setComposer(composer); DeveloperBean developer = (DeveloperBean) constructor.getSingleData(DeveloperBean.class); assertEquals("Bjarne Stroustrup", developer.name); assertEquals("C++", developer.language); }
private Object construct(Constructor constructor, String data) { StreamReader reader = new StreamReader(data); Parser parser = new ParserImpl(reader); Resolver resolver = new Resolver(); Composer composer = new Composer(parser, resolver); constructor.setComposer(composer); return constructor.getSingleData(Object.class); }
@SuppressWarnings("unchecked") private List<Object> construct(Constructor constructor, String data) { StreamReader reader = new StreamReader(data); Parser parser = new ParserImpl(reader); Resolver resolver = new Resolver(); Composer composer = new Composer(parser, resolver); constructor.setComposer(composer); List<Object> result = (List<Object>) constructor.getSingleData(Object.class); return result; }
@Override protected Yaml createYaml() { return new Yaml(new StrictMapAppenderConstructor(), new Representer(), new DumperOptions(), new Resolver() { @Override public void addImplicitResolver(Tag tag, Pattern regexp, String first) { if (tag == Tag.TIMESTAMP) { return; } super.addImplicitResolver(tag, regexp, first); } }); }
public Serializer(Emitable emitter, Resolver resolver, DumperOptions opts, Tag rootTag) { this.emitter = emitter; this.resolver = resolver; this.explicitStart = opts.isExplicitStart(); this.explicitEnd = opts.isExplicitEnd(); if (opts.getVersion() != null) { this.useVersion = opts.getVersion(); } this.useTags = opts.getTags(); this.serializedNodes = new HashSet<Node>(); this.anchors = new HashMap<Node, String>(); this.lastAnchorId = 0; this.closed = null; this.explicitRoot = rootTag; }
public JavaBeanLoader(LoaderOptions options, BeanAccess beanAccess) { if (options == null) { throw new NullPointerException("LoaderOptions must be provided."); } if (options.getRootTypeDescription() == null) { throw new NullPointerException("TypeDescription must be provided."); } Constructor constructor = new Constructor(options.getRootTypeDescription()); loader = new Yaml(constructor, options, new Representer(), new DumperOptions(), new Resolver()); loader.setBeanAccess(beanAccess); }
public JavaBeanLoader(final LoaderOptions options, final BeanAccess beanAccess) { if (options == null) { throw new NullPointerException("LoaderOptions must be provided."); } if (options.getRootTypeDescription() == null) { throw new NullPointerException("TypeDescription must be provided."); } Constructor constructor = new Constructor(options.getRootTypeDescription()); loader = new Yaml(constructor, options, new Representer(), new DumperOptions(), new Resolver()); loader.setBeanAccess(beanAccess); }
public Serializer(final Emitable emitter, final Resolver resolver, final DumperOptions opts, final Tag rootTag) { this.emitter = emitter; this.resolver = resolver; this.explicitStart = opts.isExplicitStart(); this.explicitEnd = opts.isExplicitEnd(); if (opts.getVersion() != null) { this.useVersion = opts.getVersion(); } this.useTags = opts.getTags(); this.serializedNodes = new HashSet<Node>(); this.anchors = new HashMap<Node, String>(); this.lastAnchorId = 0; this.closed = null; this.explicitRoot = rootTag; }
public Composer(Parser parser, Resolver resolver) { this.parser = parser; this.resolver = resolver; this.anchors = new HashMap<String, Node>(); this.recursiveNodes = new HashSet<Node>(); }
/** * Create Yaml instance. It is safe to create a few instances and use them * in different Threads. */ public Yaml() { this(new Constructor(), new Representer(), new DumperOptions(), new LoaderOptions(), new Resolver()); }
public FragmentComposer(Parser parser, Resolver resolver, String nodeName) { super(parser, resolver); this.nodeName = nodeName; }
@Override protected void setUp() { DumperOptions config = new DumperOptions(); StringWriter writer = new StringWriter(); serializer = new Serializer(new Emitter(writer, config), new Resolver(), config, null); }