我在尝试用JAX-RS解决此问题时遇到了麻烦,我认为这与编组/解组过程有关(我想我不太了解),我想重新创建此:
进行发布的REST端点是/ rest / register,因此我的服务定义如下:
@ApplicationPath("/rest")
public interface RestRegistration {
@POST
@Path("/register")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
String register(UsernameRegistration usernameAccess, String network) throws RegistrationException;
@POST
@Path("/register")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
String register(EmailRegistration emailAccess, String network) throws RegistrationException;
}
public class RestRegistrationImpl implements RestRegistration {
public String register(UsernameRegistration usernameAccess, String network) throws RegistrationException {
return "StackOverflow example: username=" + usernameAccess.getUser + ", network="+network;
}
public String register(EmailRegistration emailAccess, String network) throws RegistrationException{
return "StackOverflow example: email=" + emailAccess.getEmail + ", network="+network;
}
}
Run Code Online (Sandbox Code Playgroud)它应该至少接收两个不同的JSON消息:
{ "usernameAccess" …Run Code Online (Sandbox Code Playgroud)