Skip to content

Commit 057fe64

Browse files
authored
Add missing test entity class. (#1643)
Closed #1642.
1 parent 98bffc0 commit 057fe64

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2020-2023 the original author or authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.couchbase.domain;
18+
19+
import com.couchbase.client.java.json.JsonObject;
20+
import com.fasterxml.jackson.core.JsonGenerator;
21+
import com.fasterxml.jackson.core.JsonParser;
22+
import com.fasterxml.jackson.databind.JsonNode;
23+
import com.fasterxml.jackson.databind.ObjectMapper;
24+
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
25+
import com.fasterxml.jackson.databind.node.ObjectNode;
26+
import org.springframework.data.couchbase.core.mapping.Document;
27+
28+
import java.io.IOException;
29+
import java.io.InputStream;
30+
import java.io.ObjectInputStream;
31+
import java.io.ObjectOutputStream;
32+
import java.io.OutputStream;
33+
import java.io.Serializable;
34+
35+
/**
36+
* Annoted User entity for tests
37+
*
38+
* @author Michael Reiche
39+
*/
40+
41+
@Document(expiry = 1, touchOnRead = true)
42+
public class UserAnnotatedTouchOnRead extends User implements Serializable {
43+
44+
JsonNode custom = new ObjectNode(JsonNodeFactory.instance);
45+
private void writeObject(ObjectOutputStream out) throws IOException {
46+
out.defaultWriteObject();
47+
if(custom== null){
48+
out.writeBoolean(false);
49+
} else {
50+
out.writeBoolean(true);
51+
new ObjectMapper().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false).writeValue((OutputStream)out, custom);
52+
}
53+
}
54+
55+
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
56+
in.defaultReadObject();
57+
if(in.readBoolean()){
58+
this.custom = new ObjectMapper().configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false).readValue((InputStream)in, JsonNode.class);
59+
}
60+
}
61+
public UserAnnotatedTouchOnRead(String id, String firstname, String lastname) {
62+
super(id, firstname, lastname);
63+
}
64+
}

0 commit comments

Comments
 (0)