Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document serialVersionUID #163

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/io/redisearch/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
*/
public class Document implements Serializable {

private static final long serialVersionUID = 4884173545291367373L;

private static final Gson gson = new Gson();

private String id;
private double score;
private byte[] payload;
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/io/redisearch/DocumentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.redisearch;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

public class DocumentTest {

@Test
public void serialize() throws IOException, ClassNotFoundException {
String id = "9f";
double score = 10d;
Map<String, Object> map = new HashMap<>();
map.put("string", "c");
map.put("float", 12d);
byte[] payload = "1a".getBytes();
Document document = new Document(id, map, score, payload);

ByteArrayOutputStream aos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(aos);
oos.writeObject(document);
oos.flush();
oos.close();

ByteArrayInputStream ais = new ByteArrayInputStream(aos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(ais);
Document read = (Document) ois.readObject();
ois.close();

assertEquals(id, read.getId());
assertEquals(score, read.getScore(), 0d);
assertArrayEquals(payload, read.getPayload());
assertEquals("c", read.getString("string"));
assertEquals(Double.valueOf(12d), read.get("float"));
}
}