Suppress an empty xml tag

94 views
Skip to first unread message

thom...@gmail.com

unread,
Dec 2, 2023, 2:21:49 AM12/2/23
to jackson-user
I have an optional tag in my schema. If it is null, I want to not place the tag in the doc. Currently, I get

<seg/>

Which is not terrible, but not necessary.
Thanks.

Tatu Saloranta

unread,
Dec 2, 2023, 6:42:15 PM12/2/23
to jackso...@googlegroups.com
The quickest way is probably to use annotation `@JsonInclude` on POJO
or property:

@JsonInclude(JsonInclude.Include.NON_NULL)

(see `TestViews.java` test f.ex)

It is also possible change defaults with something like:

final XmlMapper mapper = XmlMapper.builder()
.changeDefaultPropertyInclusion(incl ->
incl.withValueInclusion(Include.NON_NULL))
.build();

I hope this helps,

-+ Tatu +-

> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/8c8d03ae-82c6-4eaa-86d8-57ab392eb498n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages