New libraries-data module (#2343)
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
752086e80c
commit
585597f11d
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.kryo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ComplexClass implements Serializable{
|
||||
private static final long serialVersionUID = 123456L;
|
||||
private String name = "Bael";
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.baeldung.kryo;
|
||||
|
||||
import com.esotericsoftware.kryo.DefaultSerializer;
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.KryoSerializable;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import java.util.Date;
|
||||
|
||||
@DefaultSerializer(PersonSerializer.class)
|
||||
public class Person implements KryoSerializable {
|
||||
private String name = "John Doe";
|
||||
private int age = 18;
|
||||
private Date birthDate = new Date(933191282821L);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Kryo kryo, Output output) {
|
||||
output.writeString(name);
|
||||
output.writeLong(birthDate.getTime());
|
||||
output.writeInt(age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Kryo kryo, Input input) {
|
||||
name = input.readString();
|
||||
birthDate = new Date(input.readLong());
|
||||
age = input.readInt();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.baeldung.kryo;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.Serializer;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import java.util.Date;
|
||||
|
||||
public class PersonSerializer extends Serializer<Person> {
|
||||
|
||||
@Override
|
||||
public void write(Kryo kryo, Output output, Person object) {
|
||||
output.writeString(object.getName());
|
||||
output.writeLong(object.getBirthDate()
|
||||
.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Person read(Kryo kryo, Input input, Class<Person> type) {
|
||||
Person person = new Person();
|
||||
person.setName(input.readString());
|
||||
long birthDate = input.readLong();
|
||||
person.setBirthDate(new Date(birthDate));
|
||||
person.setAge(calculateAge(birthDate));
|
||||
return person;
|
||||
}
|
||||
|
||||
private int calculateAge(long birthDate) {
|
||||
// Some custom logic
|
||||
return 18;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user