public void testStringMatcher() throws Exception { Matcher matcher = new ExampleStringMatcher(); Serializer serializer = new Persister(matcher); EmptyStringExample original = new EmptyStringExample("", null); StringWriter writer = new StringWriter(); serializer.write(original, writer); String text = writer.toString(); System.out.println(text); EmptyStringExample recovered = serializer.read(EmptyStringExample.class, text); assertEquals(recovered.emptyValue, original.emptyValue); assertEquals(recovered.nullValue, original.nullValue); }
public static Matcher matchers() { return type -> { if (type.isEnum()) { return new EnumTransform(type); } else if (type.isInstance(LocalDate.now())) { return new LocalDateTransform(); } return null; }; }
public static Persister createPersister(final Account account) { return new Persister(new Matcher() { @Override public Transform match(Class type) throws Exception { if (Date.class.isAssignableFrom(type)) { return new DateTransform(account); } else if (Uri.class.isAssignableFrom(type)) { return new UriTransform(account); } return null; } }); }
/** * Constructor for the <code>Support</code> object. This will * create a support object with the matcher and filter provided. * This allows the user to override the transformations that * are used to convert types to strings and back again. * * @param filter this is the filter to use with this support * @param matcher this is the matcher used for transformations * @param format this contains all the formatting for the XML */ public Support(Filter filter, Matcher matcher, Format format) { this.defaults = new DetailExtractor(this, FIELD); this.transform = new Transformer(matcher); this.scanners = new ScannerFactory(this); this.details = new DetailExtractor(this); this.labels = new LabelExtractor(format); this.instances = new InstanceFactory(); this.matcher = matcher; this.filter = filter; this.format = format; }
public void testLiteral() throws Exception { Matcher matcher = new LiteralMatcher(); Persister persister = new Persister(matcher); LiteralExample example = new LiteralExample("name", "key"); persister.write(example, System.out); }
public void testMatcher() throws Exception { Matcher matcher = new ExampleIntegerMatcher(); Serializer serializer = new Persister(matcher); Example example = new Example(1, 9999); serializer.write(example, System.out); validate(serializer, example); }
public void testEnumMatcher() throws Exception { Matcher matcher = new ExampleEnumMatcher(); Serializer serializer = new Persister(matcher); ExampleEnum value = new ExampleEnum(MyEnum.A_1); StringWriter writer = new StringWriter(); serializer.write(value, writer); assertElementHasAttribute(writer.toString(), "/exampleEnum", "value", "A-1"); System.out.println(writer.toString()); validate(serializer, value); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * <p> * This persister will use the provided <code>Strategy</code> to * intercept the XML elements in order to read and write persistent * data, such as the class name or version of the document. * * @param strategy this is the strategy used to resolve classes * @param matcher this is used to customize the transformations * @param filter the filter used to replace template variables */ public Persister(Strategy strategy, Filter filter, Matcher matcher, Format format) { this.support = new Support(filter, matcher, format); this.manager = new SessionManager(); this.strategy = strategy; this.format = format; }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * * @param matcher this is used to customize the transformations */ public Persister(Matcher matcher) { this(new TreeStrategy(), matcher); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * * @param matcher this is used to customize the transformations * @param format this is used to structure the generated XML */ public Persister(Matcher matcher, Format format) { this(new TreeStrategy(), matcher, format); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided filter. * This persister will replace all variables encountered when * deserializing an object with mappings found in the filter. * * @param filter the filter used to replace template variables * @param matcher this is used to customize the transformations */ public Persister(Filter filter, Matcher matcher) { this(new TreeStrategy(), filter, matcher); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided filter. * This persister will replace all variables encountered when * deserializing an object with mappings found in the filter. * * @param filter the filter used to replace template variables * @param matcher this is used to customize the transformations * @param format this is used to structure the generated XML */ public Persister(Filter filter, Matcher matcher, Format format) { this(new TreeStrategy(), filter, matcher, format); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * <p> * This persister will use the provided <code>Strategy</code> to * intercept the XML elements in order to read and write persistent * data, such as the class name or version of the document. * * @param strategy this is the strategy used to resolve classes * @param matcher this is used to customize the transformations */ public Persister(Strategy strategy, Matcher matcher) { this(strategy, new PlatformFilter(), matcher); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * <p> * This persister will use the provided <code>Strategy</code> to * intercept the XML elements in order to read and write persistent * data, such as the class name or version of the document. * * @param strategy this is the strategy used to resolve classes * @param matcher this is used to customize the transformations * @param format this is used to format the generated XML document */ public Persister(Strategy strategy, Matcher matcher, Format format) { this(strategy, new PlatformFilter(), matcher, format); }
/** * Constructor for the <code>Persister</code> object. This is used * to create a serializer object that will use the provided matcher * for customizable transformations. The <code>Matcher</code> will * enable the persister to determine the correct way to transform * the types that are not annotated and considered primitives. * <p> * This persister will use the provided <code>Strategy</code> to * intercept the XML elements in order to read and write persistent * data, such as the class name or version of the document. * * @param strategy this is the strategy used to resolve classes * @param matcher this is used to customize the transformations * @param filter the filter used to replace template variables */ public Persister(Strategy strategy, Filter filter, Matcher matcher) { this(strategy, filter, matcher, new Format()); }
/** * Constructor for the <code>Support</code> object. This will * create a support object with the matcher and filter provided. * This allows the user to override the transformations that * are used to convert types to strings and back again. * * @param filter this is the filter to use with this support * @param matcher this is the matcher used for transformations */ public Support(Filter filter, Matcher matcher) { this(filter, matcher, new Format()); }