12
12
import com .fasterxml .jackson .databind .ser .BeanSerializer ;
13
13
import com .fasterxml .jackson .databind .ser .PropertyFilter ;
14
14
import com .fasterxml .jackson .databind .ser .impl .ObjectIdWriter ;
15
+ import com .fasterxml .jackson .databind .ser .impl .WritableObjectId ;
15
16
import com .fasterxml .jackson .databind .ser .std .BeanSerializerBase ;
16
17
import com .fasterxml .jackson .databind .util .NameTransformer ;
17
18
import com .fasterxml .jackson .dataformat .xml .util .XmlInfo ;
@@ -249,6 +250,11 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
249
250
TypeSerializer typeSer )
250
251
throws IOException , JsonGenerationException
251
252
{
253
+ if (_objectIdWriter != null ) {
254
+ _serializeWithObjectId (bean , jgen , provider , typeSer );
255
+ return ;
256
+ }
257
+
252
258
/* Ok: let's serialize type id as attribute, but if (and only if!)
253
259
* we are using AS_PROPERTY
254
260
*/
@@ -264,6 +270,28 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
264
270
}
265
271
}
266
272
273
+ @ Override
274
+ protected void _serializeObjectId (Object bean ,
275
+ JsonGenerator jgen ,
276
+ SerializerProvider provider ,
277
+ TypeSerializer typeSer ,
278
+ WritableObjectId objectId ) throws IOException , JsonProcessingException ,
279
+ JsonGenerationException {
280
+ /* Ok: let's serialize type id as attribute, but if (and only if!)
281
+ * we are using AS_PROPERTY
282
+ */
283
+ if (typeSer .getTypeInclusion () == JsonTypeInfo .As .PROPERTY ) {
284
+ ToXmlGenerator xgen = (ToXmlGenerator )jgen ;
285
+ xgen .setNextIsAttribute (true );
286
+ super ._serializeObjectId (bean , jgen , provider , typeSer , objectId );
287
+ if (_attributeCount == 0 ) { // if no attributes, need to reset
288
+ xgen .setNextIsAttribute (false );
289
+ }
290
+ } else {
291
+ super ._serializeObjectId (bean , jgen , provider , typeSer , objectId );
292
+ }
293
+ }
294
+
267
295
/*
268
296
/**********************************************************
269
297
/* Helper methods
0 commit comments