下面列出了怎么用com.fasterxml.jackson.databind.annotation.JsonSerialize的API类实例代码及写法,或者点击链接到github查看源代码。
@JsonSerialize(include = Inclusion.NON_NULL)
public String getObjectName() {
if ( dataName != null ) {
return dataName;
}
if ( entities != null ) {
return "entities";
}
if ( ids != null ) {
return "ids";
}
if ( entity != null ) {
return "entity";
}
if ( id != null ) {
return "id";
}
return null;
}
@JsonSerialize
private void setState(String state) {
switch(state) {
case "in progress":
this.state = OperationState.IN_PROGRESS;
break;
case "succeeded":
this.state = OperationState.SUCCEEDED;
break;
case "failed":
this.state = OperationState.FAILED;
break;
default:
assert(false);
break;
}
}
@JsonSerialize(include = Inclusion.NON_NULL)
public UUID getId() {
if ( id != null ) {
return id;
}
if ( entity != null ) {
id = entity.getUuid();
return id;
}
if ( ( ids != null ) && ( ids.size() > 0 ) ) {
id = ids.get( 0 );
return id;
}
if ( ( entities != null ) && ( entities.size() > 0 ) ) {
entity = entities.get( 0 );
id = entity.getUuid();
return id;
}
if ( ( refs != null ) && ( refs.size() > 0 ) ) {
EntityRef ref = refs.get( 0 );
id = ref.getUuid();
}
return id;
}
@JsonSerialize(include = Inclusion.NON_NULL)
public List<Entity> getEntities() {
mergeEntitiesWithMetadata();
if ( entities != null ) {
return entities;
}
/*
* if (connectionTypeAndEntityTypeToEntityMap != null) { entities = new
* ArrayList<Entity>(); Map<UUID, Entity> eMap = new LinkedHashMap<UUID,
* Entity>(); for (String ctype :
* connectionTypeAndEntityTypeToEntityMap.keySet()) { Map<String,
* List<Entity>> m = connectionTypeAndEntityTypeToEntityMap .get(ctype);
* for (String etype : m.keySet()) { List<Entity> l = m.get(etype); for
* (Entity e : l) { if (!eMap.containsKey(e.getUuid())) { entities.add(e);
* eMap.put(e.getUuid(), e); } } } } return entities; }
*/
if ( entity != null ) {
entities = new ArrayList<Entity>();
entities.add( entity );
return entities;
}
return new ArrayList<Entity>();
}
@Override
public void propertyInclusion(JDefinedClass clazz, JsonNode schema) {
if (moduleName == null) {
moduleName = schema.get("$module").textValue();
}
if (schema.has("serializer")) {
annotateSerde(clazz, JsonSerialize.class, schema.get("serializer").asText());
}
if (schema.has("deserializer")) {
annotateSerde(clazz, JsonDeserialize.class, schema.get("deserializer").asText());
} else {
clazz.annotate(JsonDeserialize.class).param("using", JsonDeserializer.None.class);
}
super.propertyInclusion(clazz, schema);
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty
public User getSender()
{
return sender;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DXF_2_0 )
public OrganisationUnit getOrganisationUnit()
{
return organisationUnit;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public Program getProgram()
{
return program;
}
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "dataElements", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "dataElement", namespace = DxfNamespaces.DXF_2_0 )
public List<DataElement> getDataElements()
{
return dataElements;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DXF_2_0 )
public Visualization getVisualization()
{
return visualization;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public OrganisationUnitGroupSet getOrganisationUnitGroupSet()
{
return organisationUnitGroupSet;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public OrganisationUnit getOrganisationUnit()
{
return organisationUnit;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public Program getProgram()
{
return program;
}
@JsonProperty( "programStages" )
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "programStages", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "programStage", namespace = DxfNamespaces.DXF_2_0 )
public Set<ProgramStage> getProgramStages()
{
return programStages;
}
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 )
public Set<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
}
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 )
public Set<OrganisationUnit> getOrganisationUnits()
{
return organisationUnits;
}
protected boolean _useStatic(SerializerProvider provider, BeanProperty property,
JavaType referredType)
{
// First: no serializer for `Object.class`, must be dynamic
if (referredType.isJavaLangObject()) {
return false;
}
// but if type is final, might as well fetch
if (referredType.isFinal()) { // or should we allow annotation override? (only if requested...)
return true;
}
// also: if indicated by typing, should be considered static
if (referredType.useStaticType()) {
return true;
}
// if neither, maybe explicit annotation?
AnnotationIntrospector intr = provider.getAnnotationIntrospector();
if ((intr != null) && (property != null)) {
Annotated ann = property.getMember();
if (ann != null) {
JsonSerialize.Typing t = intr.findSerializationTyping(property.getMember());
if (t == JsonSerialize.Typing.STATIC) {
return true;
}
if (t == JsonSerialize.Typing.DYNAMIC) {
return false;
}
}
}
// and finally, may be forced by global static typing (unlikely...)
return provider.isEnabled(MapperFeature.USE_STATIC_TYPING);
}
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public List<TrackedEntityComment> getComments()
{
return comments;
}
@JsonProperty( "programStageSections" )
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "programStageSections", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "programStageSection", namespace = DxfNamespaces.DXF_2_0 )
public Set<ProgramStageSection> getProgramStageSections()
{
return programStageSections;
}
/**
* Get the n value.
*
* @return the n value
*/
@JsonProperty("n")
@JsonSerialize(using = Base64UrlJsonSerializer.class)
@JsonDeserialize(using = Base64UrlJsonDeserializer.class)
public byte[] n() {
return this.n;
}
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "interpretations", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "interpretation", namespace = DxfNamespaces.DXF_2_0 )
public Set<Interpretation> getInterpretations()
{
return interpretations;
}
public PublicKeyContainer( @JsonProperty( "hostId" ) final String hostId,
@JsonSerialize( using = ByteArraySerializer.class ) @JsonProperty( "fingerprint" )
final byte[] fingerprint, @JsonProperty( "key" ) final String key )
{
this.hostId = hostId;
this.fingerprint = fingerprint;
this.key = key;
}
@JsonProperty( "notificationTemplates" )
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JacksonXmlElementWrapper( localName = "notificationTemplates", namespace = DxfNamespaces.DXF_2_0 )
@JacksonXmlProperty( localName = "notificationTemplate", namespace = DxfNamespaces.DXF_2_0 )
public Set<ProgramNotificationTemplate> getNotificationTemplates()
{
return notificationTemplates;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DXF_2_0 )
public Map getMap()
{
return map;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public OrganisationUnit getOrganisationUnit()
{
return organisationUnit;
}
@JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JacksonXmlProperty( namespace = DXF_2_0 )
public int getLikes()
{
return likes;
}
@JsonSerialize( include = Inclusion.NON_NULL )
public String getUri() {
return uri;
}
@JsonProperty("customObject12s")
@JsonSerialize(using = RestOneToManySerializer.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public OneToMany<ClientCorporationCustomObjectInstance12> getCustomObject12s() {
return customObject12s;
}
@JsonSerialize
public List<BlobId> getAttachmentsNotFound() {
return attachmentsNotFound;
}
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public String getCipher() {
return cipher;
}