-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsDeductionTypeSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.fasterxml.jackson.databind.jsontype.impl; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.type.WritableTypeId; | ||
import com.fasterxml.jackson.databind.BeanProperty; | ||
|
||
/** | ||
* @since 2.14.2 | ||
*/ | ||
public class AsDeductionTypeSerializer extends TypeSerializerBase | ||
{ | ||
private final static AsDeductionTypeSerializer INSTANCE = new AsDeductionTypeSerializer(); | ||
|
||
protected AsDeductionTypeSerializer() { | ||
super(null, null); | ||
} | ||
|
||
public static AsDeductionTypeSerializer instance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public AsDeductionTypeSerializer forProperty(BeanProperty prop) { | ||
return this; | ||
} | ||
|
||
// This isn't really right but there's no "none" option | ||
@Override | ||
public As getTypeInclusion() { return As.EXISTING_PROPERTY; } | ||
|
||
@Override | ||
public WritableTypeId writeTypePrefix(JsonGenerator g, | ||
WritableTypeId idMetadata) throws IOException | ||
{ | ||
// NOTE: We can NOT simply skip writing since we may have to | ||
// write surrounding Object or Array start/end markers. But | ||
// we are not to generate type id to write (compared to base class) | ||
|
||
if (idMetadata.valueShape.isStructStart() | ||
// also: do not try to write native type id | ||
&& !g.canWriteTypeId()) { | ||
return g.writeTypePrefix(idMetadata); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public WritableTypeId writeTypeSuffix(JsonGenerator g, | ||
WritableTypeId idMetadata) throws IOException | ||
{ | ||
return (idMetadata == null) ? null | ||
: g.writeTypeSuffix(idMetadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters