Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

JSR 303 - @valid annotation is not getting generated on the List of complex type #361

Closed
gr423 opened this issue Aug 15, 2018 · 13 comments
Closed
Assignees

Comments

@gr423
Copy link

gr423 commented Aug 15, 2018

Hi Team ,

I've the below RAML

event:
type: object
properties:
  metadataset:
   required: false
   type: metadatSetType[]

metadatSetType:
  type: object
  properties:
    locale:
    required: true
    type: string
  name:
    required:false
    type: string

Generated Java Objects are as below ,

I'm expecting the @Valid annotation on the metadataSet of event .Which is not getting generated.
And the JsonMapperConfiguration is never considered while generating the code .
includeAdditionalproperties is made false , but still the java objects generated has the field.

@JsonInclude(JsonInclude.Include.NON_NULL)
Class Event
{
    @JsonProperty("metadataSet")
    List<MetadatSetType> metadataSet;
  @JsonIgnore
  private Map<String, Object> additionalProperties = new HashMap<String, Object>();
}

@JsonInclude(JsonInclude.Include.NON_NULL)
Class MetadatasetType
{
 @JsonProperty("locale")
 @NotNull
  String locale;
 @JsonProperty("name")
String name;
  @JsonIgnore
  private Map<String, Object> additionalProperties = new HashMap<String, Object>();
}

Pom File


<plugin>
<groupId>org.raml.jaxrs</groupId>
<artifactId>raml-to-jaxrs-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>GenerateAdminV2</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<ramlFile>${basedir}/src/main/resources/raml/v1/MAS_api.raml</ramlFile>
<resourcePackage>com..mas.v1.resource</resourcePackage>
<modelPackage>com..mas.v1.model</modelPackage>
<removeOldOutput>true</removeOldOutput>
<generateTypesWith>
	<value>jsr303</value>
	<value>jackson2</value>
   </generateTypesWith>
  <jsonMapperConfiguration>
	 <includeAdditionalProperties>false</includeAdditionalProperties>
</jsonMapperConfiguration>
</configuration>
</execution>
</executions>
</plugin>

@gr423
Copy link
Author

gr423 commented Aug 15, 2018

@jstoiko
Hi Jonathan,
Please can you help here ,
Basically i want to validate each element of the collection , which is provided by the Javax validation .
But since the @Valid annotation is missed on the List type in the generated code, i'm missing on the validation of the List elements .

Thanks in advance,
Ramya

@jpbelang
Copy link
Contributor

Just back from vacation, looking at it.

@jpbelang
Copy link
Contributor

includeAdditionalproperties is made false , but still the java objects generated has the field.

Have you tried the current snapshot ? I've fixed that, I think.

mulesoft-labs/raml-java-tools#12

@jpbelang
Copy link
Contributor

For the @Valid annotation, I will add it if the list contains an object type or union type (as opposed to a list type or primitive type).

String and integers require custom annotations. I know that java 8 supports annotating generic types, but right now, we have to support java 7 and this would be a major change. You could still pull it off with a plugin.

jpbelang added a commit to mulesoft-labs/raml-java-tools that referenced this issue Aug 23, 2018
I've added the @Valid annotation for unions, not sure I've got everything ok for that.
@jpbelang
Copy link
Contributor

@gr423 , could you try the SNAPSHOT please ? (On branch 3.0.3)

@jpbelang jpbelang self-assigned this Aug 23, 2018
@gr423
Copy link
Author

gr423 commented Aug 23, 2018

@jpbelang ,
Its working :) Thank you !!
The @Valid annotation is getting generated on the list type and the validations are working.
I did take the the release 3.0.3 snapshot version and built the project.
Since i build the raml-to-jaxrs project locally i was able to use raml-to-jaxrs-maven-plugin with
3.0.3-SNAPSHOT version .

Can we expect the same version in maven repository .
Sorry i'm not sure of the procedure of when the latest version of the projects gets reflected in the maven repo . Can you please throw some light on this updates .

Thanks and Regards,
Ramya

@jpbelang
Copy link
Contributor

The SNAPSHOTS are on mulesoft's repositories (I don't have them here, I'll get them for you tonight).

Building them locally is certainly ok, but if you need to share them between devs, either you upload them to your own repo or point to the mulesoft repo

@gr423
Copy link
Author

gr423 commented Aug 24, 2018 via email

@gr423
Copy link
Author

gr423 commented Sep 5, 2018

@jpbelang
Hi ,

Since our project would go to production by this month end ,i'm not able to proceed with the SNAPSHOT version .

Please could you let me know , if can expect the release version some time closer.

Or else can you suggest me the alternate, with which i can go ahead doing validations .

Thanks in advance ,
Ramya S

@jpbelang
Copy link
Contributor

jpbelang commented Sep 5, 2018

I have one bit of the Arrays bug that I need to finish, which I should do tomorrow.

I'm trying to release on the week-end.

@gr423
Copy link
Author

gr423 commented Sep 6, 2018

Thanks for the update .
Sure we will wait for the release .

Regards,
Ramya

@jpbelang
Copy link
Contributor

I've just released 3.0.3. it should come up soon on central.

@gr423
Copy link
Author

gr423 commented Sep 27, 2018

@jpbelang
Hi ,
The RAML exposed endpoints are consumed by CXF Rest Client.
But getting the issue of deserialization on retrieving the response .
The issue is asked for in stackOverflow.
https://stackoverflow.com/questions/52521191/jax-rs-client-cant-deserialize-json-response-returned-from-raml-1-0-generated-cl

Please could you give me some insight here .


Below is generated interface.
@Path("/editorialChannels")
public interface EditorialChannels {
  /**
   */
  @PUT
  @Produces("application/json")
  @Consumes("application/json")
  PutEditorialChannelsResponse putEditorialChannels(
      @Valid com.nagra.opentv.mas.v1.model.EditorialChannels entity);

  class PutEditorialChannelsResponse extends ResponseDelegate {
    private PutEditorialChannelsResponse(Response response, Object entity) {
      super(response, entity);
    }

    private PutEditorialChannelsResponse(Response response) {
      super(response);
    }

    public static PutEditorialChannelsResponse respond200WithApplicationJson(PutResponse entity) {
      Response.ResponseBuilder responseBuilder = Response.status(200).header("Content-Type", "application/json");
      responseBuilder.entity(entity);
      return new PutEditorialChannelsResponse(responseBuilder.build(), entity);
    }
}
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants