Menu

Custom Openl datatype generation to set Date format

Help
2020-07-07
2020-07-11
  • Kamal RAIMI

    Kamal RAIMI - 2020-07-07

    Hello,

    I would like to customize generation of a Openl Datatype in order to get a class file with @XmlJavaTypeAdapter annotation on a date field. The goal is to have a date format yyyy-MM-dd only for
    this date field .

    Example :

    @XmlElement(  name = "myDate",  nillable = true)
     @XmlJavaTypeAdapter(yyyyMMdd.class)
      public String getMyDate() {
          return this.myDate;
       }
    

    Thank you in advance

     
  • OpenL Tablets

    OpenL Tablets - 2020-07-09

    Hello,
    Customization of the requests and the responses for generated datatypes via MixIn classes feature was implemented OpenL 5.23.3.
    You should have an abstract class, where the getters from generated class needs are described, and then add necessary annotations.
    See an example:
    @MixInClass("org.openl.generated.beans.Customer")
    public abstract class CustomerMixIn {

    @JsonProperty(required = true)
    protected Integer customerID;
    
    @JsonIgnore
    protected Integer privateField;
    
    @JsonFormat(pattern = "yyyy-MM-dd")
    protected Date dob;
    
    @JsonProperty("genderCd")
    @ApiModelProperty(example = "male")
    protected String gender;
    

    }

    This class should be applied via rules-deploy.xml configuration file:
    <configuration>
    <entry>
    <string>rootClassNamesBinding</string>
    <string>org.example.custom.mixin.CustomerMixIn</string>
    </entry>
    </configuration>

    Best Regards,
    Alena.

     
  • Kamal RAIMI

    Kamal RAIMI - 2020-07-09

    Hi Alena,
    Great !!! Thank you for you support.
    Have a nice day
    Kamal.

     
  • Marat Kamalov

    Marat Kamalov - 2020-07-11

    Hi Kamal RAIMI,

    If you want only to customize date format for all date fields in all datatypes in a service you can to apply following configuration via rules-deploy.xml:

    <configuration>
        <entry>
            <string>jackson.defaultDateFormat</string>
            <string>dd/MM/yyyy HH:mm:ss</string>
        </entry>
    </configuration>
    

    Date format should be compatible with Java Simple date format: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

    If you want mix different date formats in datatype fields then please, use @MixInClass annotations.

    FYI, if @MixInClass is used then system doesn't generate WADL for the service, but swagger schemas works well.

    Thanks, Marat Kamalov.

     
  • Marat Kamalov

    Marat Kamalov - 2020-07-11

    if jackson.defaultDateFormat doesn't work please try jacksondatabinding.defaultDateFormat. It was renamed recently.

     

Log in to post a comment.