You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a spring-boot web project. I want to generate raml file by using the version of 0.10.14. But when the return type in controller' methods is Object, it generate any type in the json schema. The code like: @RequestMapping(value="/users")
public class UserController {
static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long, User>());
static {
users.put(1L, new User(1L, "test1", 26));
users.put(2L, new User(2L, "test2", 26));
}
@RequestMapping(value="/getUserDetail/{id}", method=RequestMethod.GET)
public Object getUser(@PathVariable Long id) {
try {
User ret = users.get(id);
return ret;
} catch (Exception e){
return new UserNotFindException(1, "user id not exists");
}
}
the User class like:
public class User { @JsonProperty(required = true)
private Long id; @JsonProperty(required = true)
private String name; @JsonProperty()
private Integer age;
}
the UserNotFindException class like:
public class UserNotFindException { @JsonProperty(required = true)
private int error_id; @JsonProperty(required = true)
private String error_msg;
public UserNotFindException(int error_id, String error_msg) {
this.error_id = error_id;
this.error_msg = error_msg;
}
}
the problem is that I want to genarate json schma in this response which represents User class, regardless of the UserNotFindException class. How can I achieve this without changing my code(the return type must be Object for some reason)?Is there an annotation?
The text was updated successfully, but these errors were encountered:
I have a spring-boot web project. I want to generate raml file by using the version of 0.10.14. But when the return type in controller' methods is Object, it generate any type in the json schema. The code like:
@RequestMapping(value="/users")
public class UserController {
}
it generate json schema in raml like:
/users:
displayName: Users Resource
description: Users Resource
/getUserDetail:
displayName: GetUserDetail Resource
description: GetUserDetail Resource
/{id}:
displayName: "{id} Resource"
description: "{id} Resource"
get:
description: getUser
responses:
"200":
description: Successful Response
body:
application/json:
schema: |
{
"type" : "any"
}
the User class like:
public class User {
@JsonProperty(required = true)
private Long id;
@JsonProperty(required = true)
private String name;
@JsonProperty()
private Integer age;
}
the UserNotFindException class like:
public class UserNotFindException {
@JsonProperty(required = true)
private int error_id;
@JsonProperty(required = true)
private String error_msg;
public UserNotFindException(int error_id, String error_msg) {
this.error_id = error_id;
this.error_msg = error_msg;
}
}
the problem is that I want to genarate json schma in this response which represents User class, regardless of the UserNotFindException class. How can I achieve this without changing my code(the return type must be Object for some reason)?Is there an annotation?
The text was updated successfully, but these errors were encountered: