这是这个问题的后续问题:
Passing custom type query parameter
我有一个包含这种方法的课程:
public static MyClass fromString(String json)
{
Gson gson = new Gson();
MyClass user = gson.fromJson(json, MyClass.class);
return user;
}
全班:
public class MyClass
{
public String name;
public PortalNameEnum portalName;
public PortalUserTypeEnum portalUserType;
public String notes;
public MyClass(String name, PortalNameEnum portalName,
PortalUserTypeEnum portalUserType, String notes)
{
super();
this.portalName = portalName;
this.portalUserType = portalUserType;
this.name = name;
this.notes = notes;
}
public static MyClass fromString(String json)
{
Gson gson = new Gson();
PortalUserInfo user = gson.fromJson(json, PortalUserInfo.class);
return user;
}
public PortalNameEnum getPortalName()
{
return portalName;
}
public void setPortalName(PortalNameEnum portalName)
{
this.portalName = portalName;
}
public PortalUserTypeEnum getPortalUserType()
{
return portalUserType;
}
public void setPortalUserType(PortalUserTypeEnum portalUserType)
{
this.portalUserType = portalUserType;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getNotes()
{
return notes;
}
public void setNotes(String notes)
{
this.notes = notes;
}
}
我有一个获得方法的资源:
@Path("/myclasscall")
@GET
@UnitOfWork
public String registerPortalUser(@Context HttpServletRequest req, @QueryParam("callback") String callback, @QueryParam("myclass") MyClass recordData) throws Throwable
{ .. }
似乎没有调用fromString
方法,并且资源方法总是为null,即使我在控制台中看到请求本身,我确实看到了一个已经传递的字符串。那是为什么?
答案 0 :(得分:0)
问题出在客户身上。 他没有传递一个名为“myclass”的参数,而是分别传递了所有字段。将它们合并到一个Json实例后,它被修复了。