// Maybe you have to correct this or use another / no Locale DateFormat format = new SimpleDateFormat("EE MMM dd HH:mm:ss z YYYY", Locale.US); RegistryMatcher m = new RegistryMatcher(); m.bind(Date.class, new DateFormatTransformer(format)); Serializer ser = new Persister(m); Example e = ser.read(Example.class, xml);
public Object read (Kryo kryo, Input input, Class type) { Cipher cipher = getCipher(Cipher.DECRYPT_MODE); CipherInputStream cipherInput = new CipherInputStream(input, cipher); return serializer.read(kryo, new Input(cipherInput, 256), type); }
public Object read (Kryo kryo, Input input, Class type) { Cipher cipher = getCipher(Cipher.DECRYPT_MODE); CipherInputStream cipherInput = new CipherInputStream(input, cipher); return serializer.read(kryo, new Input(cipherInput, 256), type); }
Serializer ser = new Persister(new AnnotationStrategy()); final String xml = "<Tournaments>\n" + " <Category category_id=\"289\">\n" + " <Tournament>aaaa</Tournament>\n" + " </Category>\n" + " <Category category_id=\"32\">\n" + " <Tournament>bbbd</Tournament>\n" + " <Tournament>cccc</Tournament>\n" + " </Category>\n" + "</Tournaments>"; Tournaments t = ser.read(Tournaments.class, xml); System.out.println(t);
@Root public class MagazinePreviews { @ElementList(name="magazines") ArrayList<MagazinePreviews> previews; public static MagazinePreviews Load(String xml) { Serializer serializer = new Persister(); return serializer.read(MagazinePreviews.class, xml); } }
/** * Reads the XML from the given InputStream using "Simple" and returns a list of assignments. * @param InputStream * @return List<Assignment> */ public List<Assignment> readSimple(final InputStream inputStream) throws Exception { Serializer serializer = new Persister(); return serializer.read(AssignmentList.class, inputStream).getAssignments(); }
Serializer serializer_Read = new Persister(); File source = new File(path); Response response = serializer_Read.read(Response.class, source); Collections.sort(response.getStations()); System.out.println("" + response.getStations().size()); for (Station station : response.getStations()) { System.out.println("" + station.getStation_id()); }
@Override public Set<T> read(Kryo kryo, Input input, Class<Set<T>> type) { int size = input.readInt(); Set<T> set = new HashSet<>(size); for (int i = 0; i < size; i++) { set.add(valSerializer.read(kryo, input, this.valType)); } return set; } }
@Override public List<T> read(Kryo kryo, Input input, Class<List<T>> type) { int size = input.readInt(); List<T> list = new ArrayList<T>(size); for (int i = 0; i < size; i++) { list.add(valSerializer.read(kryo, input, this.valType)); } return list; } }
Serializer ser = new Persister(new AnnotationStrategy()); // ^^^^^^^^^^^^^^^^^^^^ final String xml = … Response response = ser.read(Response.class, xml); System.out.println(response)
public Object read (Kryo kryo, Input input, Class type) { // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used. Inflater inflater = new Inflater(noHeaders); try { InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), inflater); return serializer.read(kryo, new Input(inflaterStream, 256), type); } finally { inflater.end(); } }
public Object read (Kryo kryo, Input input, Class type) { // The inflater would read from input beyond the compressed bytes if chunked enoding wasn't used. Inflater inflater = new Inflater(noHeaders); try { InflaterInputStream inflaterStream = new InflaterInputStream(new InputChunked(input, 256), inflater); return serializer.read(kryo, new Input(inflaterStream, 256), type); } finally { inflater.end(); } }
/* * Setting 'AnnotationStrategy' is requried here - else the Converter will get ignored. */ Serializer ser = new Persister(new AnnotationStrategy()); StringWriter sw = new StringWriter(); ser.write(DaysOfWeek.TUESDAY, sw); // ... StringReader sr = new StringReader(sw.toString()); DaysOfWeek day = ser.read(DaysOfWeek.class, sr); // ...
final File f = new File("test.xml"); // Note the new Strategy Serializer ser = new Persister(new AnnotationStrategy()); ser.write(TestStatus.AVAILABLE, f); TestStatus ts = ser.read(TestStatus.class, f); System.out.println(ts);
public static void main(String args[]) throws Exception { Serializer serializer = new Persister(new Format("<?xml version=\"1.0\" encoding= \"UTF-8\" ?>")); File source = new File("sample.xml"); Package p = serializer.read(Package.class, source); System.out.println(p.name); }
public EnumSet read (Kryo kryo, Input input, Class<EnumSet> type) { Registration registration = kryo.readClass(input); EnumSet object = EnumSet.noneOf(registration.getType()); Serializer serializer = registration.getSerializer(); int length = input.readInt(true); for (int i = 0; i < length; i++) object.add(serializer.read(kryo, input, null)); return object; }
public EnumSet read (Kryo kryo, Input input, Class<EnumSet> type) { Registration registration = kryo.readClass(input); EnumSet object = EnumSet.noneOf(registration.getType()); Serializer serializer = registration.getSerializer(); int length = input.readInt(true); for (int i = 0; i < length; i++) object.add(serializer.read(kryo, input, null)); return object; }
public EnumSet read (Kryo kryo, Input input, Class<EnumSet> type) { Registration registration = kryo.readClass(input); EnumSet object = EnumSet.noneOf(registration.getType()); Serializer serializer = registration.getSerializer(); int length = input.readInt(true); for (int i = 0; i < length; i++) object.add(serializer.read(kryo, input, null)); return object; }
final File testFile = new File("test.xml"); Settings settings = new Settings(); settings.put("a", "b"); settings.put("c", 3); settings.put("d", new Date()); // Serialize - make shure you use an AnnotationStrategy here Serializer ser = new Persister(new AnnotationStrategy()); ser.write(settings, testFile); // Deserialize Settings in = ser.read(Settings.class, testFile); System.out.println(settings.equals(in));