@@ -45,6 +45,16 @@ public class SimpleModule
45
45
protected final String _name ;
46
46
protected final Version _version ;
47
47
48
+ /**
49
+ * Flag that indicates whether module was given an explicit name
50
+ * or not. Distinction is used to determine whether method
51
+ * {@link #getTypeId()} should return name (yes, if explicit) or
52
+ * {@code null} (if no explicit name was passed).
53
+ *
54
+ * @since 2.13
55
+ */
56
+ protected final boolean _hasExplicitName ;
57
+
48
58
protected SimpleSerializers _serializers = null ;
49
59
protected SimpleDeserializers _deserializers = null ;
50
60
@@ -109,8 +119,10 @@ public SimpleModule() {
109
119
"SimpleModule-" +System .identityHashCode (this )
110
120
: getClass ().getName ();
111
121
_version = Version .unknownVersion ();
122
+ // 07-Jun-2021, tatu: [databind#3110] Not passed explicitly so...
123
+ _hasExplicitName = false ;
112
124
}
113
-
125
+
114
126
/**
115
127
* Convenience constructor that will default version to
116
128
* {@link Version#unknownVersion()}.
@@ -121,13 +133,12 @@ public SimpleModule(String name) {
121
133
122
134
/**
123
135
* Convenience constructor that will use specified Version,
124
- * including name from {@link Version#getArtifactId()}
136
+ * including name from {@link Version#getArtifactId()}.
125
137
*/
126
138
public SimpleModule (Version version ) {
127
- _name = version .getArtifactId ();
128
- _version = version ;
139
+ this (version .getArtifactId (), version );
129
140
}
130
-
141
+
131
142
/**
132
143
* Constructor to use for actual reusable modules.
133
144
* ObjectMapper may use name as identifier to notice attempts
@@ -140,6 +151,8 @@ public SimpleModule(Version version) {
140
151
public SimpleModule (String name , Version version ) {
141
152
_name = name ;
142
153
_version = version ;
154
+ // 07-Jun-2021, tatu: [databind#3110] Is passed explicitly (may be `null`)
155
+ _hasExplicitName = true ;
143
156
}
144
157
145
158
/**
@@ -166,6 +179,8 @@ public SimpleModule(String name, Version version,
166
179
List <JsonSerializer <?>> serializers )
167
180
{
168
181
_name = name ;
182
+ // 07-Jun-2021, tatu: [databind#3110] Is passed explicitly (may be `null`)
183
+ _hasExplicitName = true ;
169
184
_version = version ;
170
185
if (deserializers != null ) {
171
186
_deserializers = new SimpleDeserializers (deserializers );
@@ -181,13 +196,18 @@ public SimpleModule(String name, Version version,
181
196
* but class name (default impl) for sub-classes.
182
197
*/
183
198
@ Override
184
- public Object getTypeId () {
185
- if (getClass () == SimpleModule .class ) {
186
- return null ;
199
+ public Object getTypeId ()
200
+ {
201
+ // 07-Jun-2021, tatu: [databind#3110] Only return Type Id if name
202
+ // was explicitly given
203
+ if (_hasExplicitName ) {
204
+ return _name ;
187
205
}
188
- return super .getTypeId ();
206
+ // ...otherwise give no type id, even for sub-classes (sub-classes are
207
+ // welcome to override this method of course)
208
+ return null ;
189
209
}
190
-
210
+
191
211
/*
192
212
/**********************************************************
193
213
/* Simple setters to allow overriding
0 commit comments