Skip to content

Commit

Permalink
Document serialVersionUID (#163)
Browse files Browse the repository at this point in the history
* Document serialVersionUID

* old serialVersionUID
  • Loading branch information
sazzad16 authored Aug 25, 2021
1 parent 2e54b92 commit 2702412
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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"));
}
}

0 comments on commit 2702412

Please sign in to comment.