Skip to content

Commit 90479d3

Browse files
committed
minor cleanup
1 parent 5d7576c commit 90479d3

File tree

1 file changed

+63
-73
lines changed

1 file changed

+63
-73
lines changed

src/test/java/com/fasterxml/jackson/databind/objectid/JSOGDeserialize622Test.java

Lines changed: 63 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
package com.fasterxml.jackson.databind.objectid;
22

3-
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
3+
import com.fasterxml.jackson.annotation.*;
64
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
75
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
8-
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
6+
97
import com.fasterxml.jackson.core.JsonParser;
10-
import com.fasterxml.jackson.databind.BaseMapTest;
11-
import com.fasterxml.jackson.databind.DeserializationContext;
12-
import com.fasterxml.jackson.databind.JsonDeserializer;
13-
import com.fasterxml.jackson.databind.JsonMappingException;
14-
import com.fasterxml.jackson.databind.JsonNode;
15-
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
import com.fasterxml.jackson.databind.*;
1610
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1711

1812
import java.io.IOException;
@@ -27,88 +21,81 @@ public class JSOGDeserialize622Test extends BaseMapTest
2721
public static final String REF_KEY = "@ref";
2822

2923
/**
30-
* JSON input
31-
*/
32-
private static final String EXP_EXAMPLE_JSOG = aposToQuotes(
33-
"{'@id':'1','foo':66,'next':{'"+REF_KEY+"':'1'}}");
34-
35-
/**
36-
* Customer IdGenerator
24+
* Custom IdGenerator
3725
*/
3826
static class JSOGGenerator extends ObjectIdGenerator<JSOGRef> {
27+
private static final long serialVersionUID = 1L;
28+
protected transient int _nextValue;
29+
protected final Class<?> _scope;
3930

40-
private static final long serialVersionUID = 1L;
41-
protected transient int _nextValue;
42-
protected final Class<?> _scope;
31+
protected JSOGGenerator() { this(null, -1); }
4332

44-
protected JSOGGenerator() { this(null, -1); }
45-
46-
protected JSOGGenerator(Class<?> scope, int nextValue) {
47-
_scope = scope;
48-
_nextValue = nextValue;
49-
}
33+
protected JSOGGenerator(Class<?> scope, int nextValue) {
34+
_scope = scope;
35+
_nextValue = nextValue;
36+
}
5037

51-
@Override
52-
public Class<?> getScope() {
53-
return _scope;
54-
}
38+
@Override
39+
public Class<?> getScope() {
40+
return _scope;
41+
}
5542

56-
@Override
57-
public boolean canUseFor(ObjectIdGenerator<?> gen) {
58-
return (gen.getClass() == getClass()) && (gen.getScope() == _scope);
59-
}
43+
@Override
44+
public boolean canUseFor(ObjectIdGenerator<?> gen) {
45+
return (gen.getClass() == getClass()) && (gen.getScope() == _scope);
46+
}
6047

61-
@Override
62-
public ObjectIdGenerator<JSOGRef> forScope(Class<?> scope) {
63-
return (_scope == scope) ? this : new JSOGGenerator(scope, _nextValue);
64-
}
48+
@Override
49+
public ObjectIdGenerator<JSOGRef> forScope(Class<?> scope) {
50+
return (_scope == scope) ? this : new JSOGGenerator(scope, _nextValue);
51+
}
6552

66-
@Override
67-
public ObjectIdGenerator<JSOGRef> newForSerialization(Object context) {
68-
return new JSOGGenerator(_scope, 1);
69-
}
53+
@Override
54+
public ObjectIdGenerator<JSOGRef> newForSerialization(Object context) {
55+
return new JSOGGenerator(_scope, 1);
56+
}
7057

71-
@Override
72-
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
73-
return new IdKey(getClass(), _scope, key);
74-
}
58+
@Override
59+
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key) {
60+
return new IdKey(getClass(), _scope, key);
61+
}
7562

76-
// important: otherwise won't get proper handling
77-
@Override
78-
public boolean maySerializeAsObject() { return true; }
63+
// important: otherwise won't get proper handling
64+
@Override
65+
public boolean maySerializeAsObject() { return true; }
7966

80-
// ditto: needed for handling Object-valued Object references
81-
@Override
82-
public boolean isValidReferencePropertyName(String name, Object parser) {
83-
return REF_KEY.equals(name);
84-
}
67+
// ditto: needed for handling Object-valued Object references
68+
@Override
69+
public boolean isValidReferencePropertyName(String name, Object parser) {
70+
return REF_KEY.equals(name);
71+
}
8572

86-
@Override
87-
public JSOGRef generateId(Object forPojo) {
88-
int id = _nextValue;
89-
++_nextValue;
90-
return new JSOGRef(id);
91-
}
73+
@Override
74+
public JSOGRef generateId(Object forPojo) {
75+
int id = _nextValue;
76+
++_nextValue;
77+
return new JSOGRef(id);
78+
}
9279
}
9380

9481
/**
9582
* The reference deserializer
9683
*/
9784
static class JSOGRefDeserializer extends JsonDeserializer<JSOGRef>
9885
{
99-
@Override
100-
public JSOGRef deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
101-
JsonNode node = p.readValueAsTree();
102-
if (node.isTextual()) {
103-
return new JSOGRef(node.asInt());
104-
}
105-
JsonNode n = node.get(REF_KEY);
106-
if (n == null) {
107-
throw new JsonMappingException(p, "Could not find key '"+REF_KEY
108-
+"' from ("+node.getClass().getName()+"): "+node);
109-
}
110-
return new JSOGRef(n.asInt());
111-
}
86+
@Override
87+
public JSOGRef deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
88+
JsonNode node = p.readValueAsTree();
89+
if (node.isTextual()) {
90+
return new JSOGRef(node.asInt());
91+
}
92+
JsonNode n = node.get(REF_KEY);
93+
if (n == null) {
94+
throw new JsonMappingException(p, "Could not find key '"+REF_KEY
95+
+"' from ("+node.getClass().getName()+"): "+node);
96+
}
97+
return new JSOGRef(n.asInt());
98+
}
11299
}
113100

114101
/**
@@ -204,6 +191,9 @@ public static class Outer {
204191
// Basic for [databind#622]
205192
public void testStructJSOGRef() throws Exception
206193
{
194+
final String EXP_EXAMPLE_JSOG = aposToQuotes(
195+
"{'@id':'1','foo':66,'next':{'"+REF_KEY+"':'1'}}");
196+
207197
IdentifiableExampleJSOG result = MAPPER.readValue(EXP_EXAMPLE_JSOG,
208198
IdentifiableExampleJSOG.class);
209199
assertEquals(66, result.foo);

0 commit comments

Comments
 (0)