Jersey对象的fromString方法未调用 [英] Jersey object's fromString method is not called

查看:64
本文介绍了Jersey对象的fromString方法未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是该问题的后续问题:

This is a follow up question to this question:

传递自定义类型查询参数

我有一个包含此方法的类:

I got a class which includes this method:

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;
}

}

我有一个资源,有一个方法:

I got a resource which got a method:

@Path("/myclasscall")
@GET
@UnitOfWork
public String registerPortalUser(@Context HttpServletRequest req, @QueryParam("callback") String callback, @QueryParam("myclass") MyClass recordData) throws Throwable
{ .. }

似乎没有调用fromString方法,资源方法始终为null,即使我在控制台中看到了请求本身,并且确实看到了已传递的字符串.为什么会这样?

It seems like the fromString method is not called and the resource method is always null, even though I see in the console the request itself and I do see a string that has been passed. Why is that?

推荐答案

问题出在客户端上. 他没有传递一个名为"myclass"的参数,而是分别传递了所有字段.将它们合并到一个Json实例中后,它已修复.

The problem was with the client. Instead of passing a single parameter called "myclass", he passed all the fields separately. After merging them together into a single Json instance, it was fixed.

这篇关于Jersey对象的fromString方法未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆