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 ;
@@ -256,6 +257,11 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
256
257
TypeSerializer typeSer )
257
258
throws IOException , JsonGenerationException
258
259
{
260
+ if (_objectIdWriter != null ) {
261
+ _serializeWithObjectId (bean , jgen , provider , typeSer );
262
+ return ;
263
+ }
264
+
259
265
/* Ok: let's serialize type id as attribute, but if (and only if!)
260
266
* we are using AS_PROPERTY
261
267
*/
@@ -271,6 +277,28 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide
271
277
}
272
278
}
273
279
280
+ @ Override
281
+ protected void _serializeObjectId (Object bean ,
282
+ JsonGenerator jgen ,
283
+ SerializerProvider provider ,
284
+ TypeSerializer typeSer ,
285
+ WritableObjectId objectId ) throws IOException , JsonProcessingException ,
286
+ JsonGenerationException {
287
+ /* Ok: let's serialize type id as attribute, but if (and only if!)
288
+ * we are using AS_PROPERTY
289
+ */
290
+ if (typeSer .getTypeInclusion () == JsonTypeInfo .As .PROPERTY ) {
291
+ ToXmlGenerator xgen = (ToXmlGenerator )jgen ;
292
+ xgen .setNextIsAttribute (true );
293
+ super ._serializeObjectId (bean , jgen , provider , typeSer , objectId );
294
+ if (_attributeCount == 0 ) { // if no attributes, need to reset
295
+ xgen .setNextIsAttribute (false );
296
+ }
297
+ } else {
298
+ super ._serializeObjectId (bean , jgen , provider , typeSer , objectId );
299
+ }
300
+ }
301
+
274
302
/*
275
303
/**********************************************************
276
304
/* Helper methods
0 commit comments