I want to validate list of string (ccEmailAddresses) in my pojo. I'm using Jsonschema2pojo to create Java pojo from json.
Json -
{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "Email Recipient",
"description": "Schema for an email recipient document.",
"type": "object",
"additionalProperties": false,
"required": true,
"properties": {
"firstName": {
"type": "string",
"maxLength": 30
},
"lastName": {
"type": "string",
"minLength": 1,
"maxLength": 50
},
"emailAddress": {
"type": "string",
"pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
"maxLength": 255,
"required": true
},
"ccEmailAddresses": {
"type": "array",
"items": {
"type" : "string",
"pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$"
}
}
}
}
As given above, pattern does not validate ccEmailAddresses. However it does validate emailAddress. So for single element it just works fine but not for list.
Further I tried putting pattern as -
{
"$schema": "http://json-schema.org/draft-03/schema",
"title": "Email Recipient",
"description": "Schema for an email recipient document.",
"type": "object",
"additionalProperties": false,
"required": true,
"properties": {
"firstName": {
"type": "string",
"maxLength": 30
},
"lastName": {
"type": "string",
"minLength": 1,
"maxLength": 50
},
"emailAddress": {
"type": "string",
"pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
"maxLength": 255,
"required": true
},
"ccEmailAddresses": {
"type": "array",
"pattern": "|^[\\w-']+(?:[\\.\\+&=][\\w-']+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,10}$",
"items": {
"type" : "string"
}
}
}
}
Even this doesn't work. I would not prefer moving out from Jsonschema2pojo because of this. I couldn't find any documentation on this but this must be very common use case.
Any help would be highly appreciated.
Thanks,