我正在使用 GSON 将名为Profile的 JPA 实体从我的服务器传递到客户端
@Entity
public class Profile implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
.
.
.
}
GSON 代码:
Gson gson = new Gson();
Profile profile = gson.fromJson(json, Profile.class);
但我得到:
java.lang.NoClassDefFoundError: javax.persistence.Id
java.lang.reflect.Field.getDeclaredAnnotations(Native Method)
java.lang.reflect.Field.getDeclaredAnnotations(Field.java:188)
java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:188)
java.lang.reflect.AccessibleObject.getAnnotation(AccessibleObject.java:196)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldName(ReflectiveTypeAdapt erFactory.java:60)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson.getAdapter(Gson.java:353)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.<init>(ReflectiveTypeAdapterFactory.java:82)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:81)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:118)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:72)
com.google.gson.Gson.getAdapter(Gson.java:353)
com.google.gson.Gson.fromJson(Gson.java:754)
com.google.gson.Gson.fromJson(Gson.java:721)
com.google.gson.Gson.fromJson(Gson.java:670)
com.google.gson.Gson.fromJson(Gson.java:642)
我需要做什么来解决这个问题?