GWT Bean Validation (jsr-303) and xml config - java

I am building a sort of validation framework for a GWT project.
The point is to reuse the same validation code for both client and server side.
I found that jsr-303 Bean Validation is supported by both GWT(here) and Spring(here).
As my model object are generated and I cannot annotate them properly, I would like to use xml-based configuration for jsr-303 Bean Validation. However, I don't see a way of doing it with gwt-validation.
Is there a way I configure the gwt-validation using xml instead of annotations?

It looks like there's no way of doing this yet.

Related

Bean validation and SOAP fault messages

I'm learning bean validation and want to apply it in a webservice.
I would like to build a SOAP web service, implementing it using EJBs. Port implementation is facade to internal implementation structure.
As transport objects I generated classes from XML schema, while in internal structure I use JPA entities.
I would like to use bean validation annotations on JPA entities and EJB methods.
Is it possible somehow to use constraint violations as validation results in the facade to build fault messages?
Is there any good practice how to achieve that, since xsd types and jpa entities have slightly different structure and direct messages from validation might not be totally suitable for faults?

SpringBoot application ignore xml configuration for HibernateValidator

My question is the following:
Is it possible to ignore XML configuration for HibernateValidator, i.e. exclude validation.xml parsing in a SpringBoot application?
I do not have the need for a validation.xml in my application, but I see that when the application starts up, it tries to parse this file.
I found this in the Hibernate Validator documentation (https://docs.jboss.org/hibernate/validator/4.1/reference/en-US/html/validator-xmlconfiguration.html):
It is even possible to ignore the XML configuration completely via Configuration.ignoreXmlConfiguration().
What I see is, that in the LocalValidatorFactoryBean.afterPropertiesSet() method, the configuration is created for the validator. This bean has a method called postProcessConfiguration(Configuration configuration), which is called before the validatorFactory is built from the configuration.
It seemed an ideal place to call the ignoreXmlConfiguration() method, what the documentation suggested.
I tried to extend this LocalValidatorFactoryBean, so that I can implement this call in the above mentioned method. Then I tried to load this bean via java configuration class.
Unfortunately some bootstrapping mechanism already uses the Spring provided bean, before it finds mine, the two beans run at the same time. I saw the message saying that XML configuration is ignored the with the bean I created, however, this solution did not help, because the Spring provided bean is not substituted with mine.
I also tried to find if there is any application property that I can use, or exclude some autoconfiguration, but no luck.
Any ideas? :)
UPDATE:
I tried excluding the HibernateJPAAutoConfiguration, it didn't help.
If you dont need hibernate validator then remove all dependency related to hibernate validator from pom.xml file.
you can also try #EnableAutoConfiguration(excludes=) annotation adding on your Application class to exclude default validation configuration.
like #SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class,DataSourceAutoConfiguration.class} })

Can I suppress a public bean property in Spring RESTful MVC JSON serialization?

I have s simple Java bean class without any annotations or configuration that is being serialized to JSON by Spring RESTful MVC (also without any configuration, just the defaults that come with Spring Boot).
Everything works fine, except that I have a few public convenience getters that calculate some derived properties that I don't want to have included in the JSON.
What is the best way to suppress a single property from JSON serialization?
It depends on which parser your application is using under the hood. Most probably it's Jackson and adding #JsonIgnore annotation to the attribute should work.

Generate a xsd for a JSR-303 annotation-based bean

Is there a tool or maven plugin to generate a xsd-file for a JSR-303 annotation-based bean? I use SpringMVC for my REST services and validate the beans using JSR-303. Now i want to generate for based on the beans xsd files.
I assume you re asking about generating XML configuration files. The xsd files are schema files the configuration files have to adhere to. For JSR 303 the schema file can be found at http://www.jboss.org/xml/ns/javax/validation/mapping/validation-mapping-1.0.xsd.
From what do you want to create the xml configuration from? From already annotated entities (annotations are the default configuration source which can be overridden by xml)? Or do you want to create xml configuration files from scratch? For the former, I don't think that there are any tools which generate Bean Validation xml configuration files from annotated entities. For the latter, some IDEs (for example Idea) have some basic support for Bean Validation and its xml configuration.
Is this answering your question?

JBoss bean validation needs to call an EJB

I am writing bean validation on my persistence model. I need to call my EJB Bean in order to retrieve some configuration parammeter from DB. How can I achieve this?
I tried to mark my EntityValidator as #Stateless and #LocalBean, but JBoss is still treats my EntityValidator as POJO. Can I do something about it? Alternatively, how can I retrieve EJB from POJO.
As of Bean Validation 1.0, you can't get EJBs injected into validators out of the box. This will change with Bean Validation 1.1, though.
Currently you have the following possibilities:
Retrieve the EJB via JNDI: MyEjb myEjb = InitialContext.doLookup(myEjbName);
Implement a custom ConstraintValidatorFactory which injects EJB references into created validator objects
Use Seam Validation, which enables dependency injection for validator objects using #Inject (disclaimer: I'm the author of Seam Validation)
With Bean 1.1 this will be possible out of box.
Currently, injection is not working in validators.
I've read that there are plans for future extension of bean validaton to enable exactly that behaviour.
However, there should be extension like seam or deltaspike, which could enabled you to provide injection.
Check this:
injection in validators
I don't think jboss will inject your bean to the JPA validator.
You can use JDNI to lookup your EJB for POJO.

Categories