Jackson and Swagger - default value for Set - spring-boot

I wish attribute "certificados" should be initialized with empty Set "[]"
I have tried JsonSetter and also initialize attribute, but without success
"certificados" is exposed that way

Problem solved using the configuration below

Related

Get session attribute having attribute name in a constants file

I want to get a session attribute from xhtml file. I know that if you put the attribute name like this #{sessionAttributeName.field} it works but my problem comes when I try to get the attribute name from a constants file.
I've imported the constants file with <p:importConstants type="Constants" var="constants"/>
I've tried get the attribute using #{constants.constantAttributeName.field} (constantAttributeName value is sessionAttributeName) but, how I expected, it doesn't work.
Is it possible get the session attribute using the constant with another method or another way to do this?
I could put directly the attribute name in all xhtml files, but if it changes, I should change all files.
Do you have idea?
I've solved it. I've used #{sessionScope[constants.constantAttributeName].field} and now it's working.

#RequestHeader required property behavior for request paramter and value

Can we make a header parameter mandatory but not the value using #RequestHeader?
For example if we use,
#RequestHeader(value = "abc", required = true)
both parameter and it value has to be there.
Edit:
Suppose i call some rest api has above request header param with "abc" but no value. So in this case i am able to invoke the rest api successfully since i have invoke with "abc" header param even i did not enter a value to it. Due to some governance tool rule, i need to have a specific header param but i dont want force user to enter any value.
Spring 5.2 and lower
The #RequestHeader doesn't provide additional facility to check the value of the parameter to be mandatory i.e. not null.
Given below are the available fields as per Spring Doc
defaultValue: The default value to use as a fallback.
name: The name of the request header to bind to.
required: Whether the header is required; null values are allowed
value: Alias for name()
So what you can do is read the parameter either with the help of #RequestHeader or inject a HttpServletRequest request, read by request.getHeader(...) and check inside the controller method if the value exists and then can call methods to perform the necessary logic.
Although you can make sure that the parameter exists with the help of required attribute for e.g. #RequestHeader(value = "Authorization", required = true) String authorization).
Spring 5.3+
The required field was tightened up, both the property and the value should exist. From the release notes:
The #RequestHeader annotation detect a null conversion result value and treat it as missing. In order to allow an empty value to be injected as a null argument, either set required=false on the argument annotation, e.g. #RequestParam(required=false), or declare the argument as #Nullable.
As #Mudassar said, #RequestHeader doesn't provide additional facility to check the value of the parameter to be mandatory i.e. not null.
It is related to this issue: https://github.com/spring-projects/spring-framework/issues/23939
I developed a workaround for this problem using an annotation #RequestHeaderNonNull that I've created: https://github.com/armandoalmeida/request-header-required-non-null
I hope I've helped you!

Can I get saml-token as string?

I am using spring-security-saml2 1.0.0.RELEASE.
It works well and pretty good for me.
But New requirement is rised. I need saml-token as string.
can I get the saml-token as string. I find saml-token in log.
But how to get the saml-token as string format?
Good question, I've just added a new chapter to the Spring SAML manual which addresses this issue:
Authentication assertion
Assertion used to authenticate user is stored in the
SAMLCredential object under property authenticationAssertion. By
default the original content (DOM) of the assertion is discarded and
system only keeps an unmarshalled version which might slightly differ
from the original, e.g. in white-spaces. In order to instruct Spring
SAML to keep the assertion in the original form (keep its DOM) set
property releaseDOM to false on bean WebSSOProfileConsumerImpl.
Assertion can be serialized to String using the following call:
XMLHelper.nodeToString(SAMLUtil.marshallMessage(credential.getAuthenticationAssertion()))

Get Thymeleaf #{} expression to append locale

My context path is / and I'm adding locales directly as part of the path: /de/index.html.
Now I'm facing the problem that th:href="#{/login.html}" will resolve to /login.html instead of /de/login.html.
I already tried making a Filter and an Interceptor like they did it here: https://stackoverflow.com/a/23847484/1163457
But it still won't append de/ after the context path.
Writing my own dialect and attribute processors would be a solution, but isn't there any better one?
Why not expose a model attribute for the locale (e.g. curLocale) and redefine all your urls like
th:href="#{/${curLocale}/login.html}"
Thymeleaf allows other expressions inside url expressions themselves.
Locale information is easily accessible either as a method parameter or by calling RequestContext.getLocale()
I found a clean and good solution myself after hours of step debugging:
https://stackoverflow.com/a/60103777/1163457

Spring MVC: Set property to null when bind fails

Is it possible to configure Spring to set the target property to null when binding fails?
For example, my bean has a date property which can have a pre-existing value when the form is displayed. If the user enters an invalid date, I want the property to be set to null; currently it retains its previous value.
I still want the binding error of course, so I can display an error message.
I'm hoping there's a general configuration solution for this (ie. I don't want to just write code to deal with each field manually!).
Background: Retaining the old value causes odd behaviour in subsequent custom cross-field validation. Setting the property values to null would tell this validation not to execute.

Resources