Skip to content

Commit ed6e93d

Browse files
committed
Fix JD serializability
1 parent 5f9492f commit ed6e93d

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroMapper.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public Builder(AvroFactory f) {
3535
addModule(new AvroModule());
3636
}
3737

38+
public Builder(StateImpl state) {
39+
super(state);
40+
// no need to add module, should come by default
41+
}
42+
3843
@Override
3944
public AvroMapper build() {
4045
return new AvroMapper(this);
@@ -43,7 +48,7 @@ public AvroMapper build() {
4348
@Override
4449
protected MapperBuilderState _saveState() {
4550
// nothing extra, just format features
46-
return new MapperBuilderState(this);
51+
return new StateImpl(this);
4752
}
4853

4954
/*
@@ -99,6 +104,23 @@ public Builder configure(AvroGenerator.Feature feature, boolean state)
99104
}
100105
return this;
101106
}
107+
108+
protected static class StateImpl extends MapperBuilderState
109+
implements java.io.Serializable // important!
110+
{
111+
private static final long serialVersionUID = 3L;
112+
113+
public StateImpl(Builder src) {
114+
super(src);
115+
}
116+
117+
// We also need actual instance of state as base class can not implement logic
118+
// for reinstating mapper (via mapper builder) from state.
119+
@Override
120+
protected Object readResolve() {
121+
return new Builder(this).build();
122+
}
123+
}
102124
}
103125

104126
/*

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonObjectMapper.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,36 @@ public Builder(IonFactory f) {
6868
addModule(m);
6969
}
7070

71+
public Builder(StateImpl state) {
72+
super(state);
73+
// other stuff should have been preserved along with state
74+
}
75+
7176
@Override
7277
public IonObjectMapper build() {
7378
return new IonObjectMapper(this);
7479
}
7580

7681
@Override
7782
protected MapperBuilderState _saveState() {
78-
return new MapperBuilderState(this);
83+
return new StateImpl(this);
84+
}
85+
86+
protected static class StateImpl extends MapperBuilderState
87+
implements java.io.Serializable // important!
88+
{
89+
private static final long serialVersionUID = 3L;
90+
91+
public StateImpl(Builder src) {
92+
super(src);
93+
}
94+
95+
// We also need actual instance of state as base class can not implement logic
96+
// for reinstating mapper (via mapper builder) from state.
97+
@Override
98+
protected Object readResolve() {
99+
return new Builder(this).build();
100+
}
79101
}
80102
}
81103

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufMapper.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,35 @@ public Builder(ProtobufFactory f) {
3434
super(f);
3535
}
3636

37+
public Builder(StateImpl state) {
38+
super(state);
39+
}
40+
3741
@Override
3842
public ProtobufMapper build() {
3943
return new ProtobufMapper(this);
4044
}
4145

4246
@Override
4347
protected MapperBuilderState _saveState() {
44-
return new MapperBuilderState(this);
48+
return new StateImpl(this);
49+
}
50+
51+
protected static class StateImpl extends MapperBuilderState
52+
implements java.io.Serializable // important!
53+
{
54+
private static final long serialVersionUID = 3L;
55+
56+
public StateImpl(Builder src) {
57+
super(src);
58+
}
59+
60+
// We also need actual instance of state as base class can not implement logic
61+
// for reinstating mapper (via mapper builder) from state.
62+
@Override
63+
protected Object readResolve() {
64+
return new Builder(this).build();
65+
}
4566
}
4667
}
4768

0 commit comments

Comments
 (0)