0

我遇到了很多我认为对解决我的问题没有帮助的异常,

这是他们

Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl$EntityInstrumentationMetadataImpl with modifiers "public"

这是我返回 JSON 的操作类

public class GetTagsAction extends ActionSupport{       
    public String execute(){

        Gson gson = new Gson();
        String tags = gson.toJson(audioTaggingService.findTagsByName(q));
        System.out.println(tags);

        return Action.SUCCESS;
    }

    public String getQ() {
        return q;
    }

    public void setQ(String q) {
        this.q = q;
    }

    public AudioTaggingService getAudioTaggingService() {
        return audioTaggingService;
    }

    public void setAudioTaggingService(AudioTaggingService audioTaggingService) {
        this.audioTaggingService = audioTaggingService;
    }

    public String getTags() {
        return tags;
    }

    public void setTags(String tags) {
        this.tags = tags;
    }

    private String q;
    private AudioTaggingService audioTaggingService;
    private String tags;
}

这是包裹

<package name="default" namespace="/" extends="json-default">
    <!--  Get AJAX Related Actions -->
    <action name="tags" class="tags">
        <result type="json" />
    </action>
</package>

我正在使用Struts2-JSON-plugin

4

3 回答 3

3

错误是由于插件正在尝试转换整个对象图,并且看起来插件正在尝试通过 audioTaggingService 转换您的数据库层。您需要在 struts XML 中指定“root”参数

<action name="tags" class="tags">
    <result type="json">
      <param name="root">tags</param>
    </result>
</action>

并在您的操作中提供一个 getTags() 方法。

但是,我不确定这是否会有所帮助。我不确定当您尝试对已经包含 JSON 数据的字符串进行 JSON 化处理时会发生什么。

于 2013-01-30T13:02:48.077 回答
2

您需要在 xml 中编辑以下行

 <action name="tags" class="tags">

属性class正在寻找详细的类名称,例如com.your.package.YourAction

详细在这里

于 2013-01-30T08:53:12.450 回答
0

如果 JSON 数据之一为空,则有时会出现此错误,转换时不会出错,但在处理数据时会出错。

于 2014-11-27T07:19:56.910 回答