I have a Cloud Endpoints method that begins like this:
@ApiMethod(httpMethod = HttpMethod.POST, path = "kokoers")
public Kokoer createKokoer(Kokoer kokoer, User user) throws UnauthorizedException, BadRequestException {
logger.info(new ObjectMessage("kokoer: " + kokoer));
I am testing it with curl like this:
curl --request POST --header "content-Typ: application/json" -H "Authorization: Bearer <JWT token>" --data '{"kokoerName":"Danny Dwob", "emailAddress":"me@there"}' http://localhost:8080/_ah/api/kokodokoapi/v1/kokoers/
The logged message from my method is:
09:32:08.940 [qtp2009787198-57] INFO uk.co.scapps.kokodoko.api.KokodokoAPI - kokoer: Kokoer [kokoer_id=null, kokoerName=null, no. of kokos=0, periods=[], emailAddress=null, kokoSharingPolicy=null]
I was expecting that kokoerName and emailAddress would have non-null values.
The path definition in my openapi.json file looks like this:
"paths": {
"/kokodokoapi/v1/kokoers": {
"post": {
"operationId": "KokodokoapiCreateKokoer",
"parameters": [
{
"in": "body",
"name": "body",
"required": false,
"schema": {
"$ref": "#/definitions/Kokoer"
}
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/Kokoer"
}
}
},
"security": [
{
"firebase": []
}
],
"x-security": [
{
"firebase": {
"audiences": [
"<project id>"
]
}
}
]
}
},
and the Kokoer definition in that file looks like this:
"Kokoer": {
"properties": {
"emailAddress": {
"type": "string"
},
"kokoSharingPolicy": {
"$ref": "#/definitions/KokoSharingPolicy_E"
},
"kokoerName": {
"type": "string"
},
"kokoer_id": {
"type": "integer",
"format": "int64"
},
"kokos": {
"type": "array",
"items": {
"$ref": "#/definitions/Koko"
}
},
"periods": {
"type": "array",
"items": {
"$ref": "#/definitions/KokoPeriod"
}
}
}
}
The relevant (as I understand it; happy to be corrected) portions of the Kokoer class definition look like this:
package uk.co.scapps.kokodoko.datamodel;
import java.util.HashSet;
import java.util.Set;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonManagedReference;
@Entity(name="Kokoer")
@Table(name="kokoer")
public class Kokoer {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(updatable = false, nullable = false)
private Long kokoer_id;
private String kokoerName;
@OneToMany(mappedBy = "kokoer")
@JsonManagedReference
private Set<Koko> kokos = new HashSet<Koko>();
. . .
public String getKokoerName() {
return this.kokoerName;
}
public void setKokoerName(String kokoerName) {
this.kokoerName = kokoerName;
}
public Kokoer() {
super();
// TODO Auto-generated constructor stub
}
}
The method otherwise runs entirely as expected given that the input Kokoer object has all null field values instead of the values I am passing in from curl.
I have one other API method in the project so far for creating objects of a similar type. It is structured in an extremely similar way, and it works as expected including the input values from curl appearing in the input object. I cannot spot a structural difference between the two to explain the different behavior.
Any thoughts?
Thanks.
-Dan