java.lang.IllegalArgumentException:类java.util.concurrent.AtomicInteger声明多个名为serialVersionUID的JSON字段
我得到了gson错误:java.lang.IllegalArgumentException:class java.util.concurrent.AtomicInteger声明了多个名为serialVersionUID的JSON字段 以下是我的课程:java.lang.IllegalArgumentException:类java.util.concurrent.AtomicInteger声明多个名为serialVersionUID的JSON字段,java,json,gson,Java,Json,Gson,我得到了gson错误:java.lang.IllegalArgumentException:class java.util.concurrent.AtomicInteger声明了多个名为serialVersionUID的JSON字段 以下是我的课程: public abstract class Points { private static Points instance = getBPointsImpl(); public static Points getInstance() {
public abstract class Points {
private static Points instance = getBPointsImpl();
public static Points getInstance() {
return instance;
}
private static Points getBPointsImpl() {
return new JSONPoints();
}
public abstract void clean();
public abstract void forceSave();
public abstract void forceSave(boolean sync);
public abstract GLocation getSpawn();
public abstract void setSpawn(GLocation loc);
public abstract GLocation getPoint(String id);
public abstract void addPoint(String id, GLocation loc);
public abstract void removePoint(String id);
public abstract void load();
}
类扩展点
public abstract class MemoryPoints extends Points {
public GLocation spawn;
public Map<String, GLocation> points = new ConcurrentSkipListMap<String, GLocation>();
@Override
public void clean() {
}
@Override
public GLocation getSpawn() {
return spawn;
}
@Override
public void setSpawn(GLocation loc) {
this.spawn = loc;
}
@Override
public GLocation getPoint(String id) {
return points.get(id);
}
@Override
public void addPoint(String id, GLocation loc) {
points.put(id, loc);
}
@Override
public void removePoint(String id) {
points.remove(id);
}
@Override
public abstract void forceSave();
@Override
public abstract void load();
}
编辑:
告诉我你们还需要什么 问题在于GSON无法识别库中某个类的序列id,所以我只是为它创建了自己的包装器,实现了Serializable并使用了一个新的序列id。我想知道当代码中没有一个
AtomicInteger
时,为什么它在AtomicInteger
上有问题。您是否向我们展示了许多不相关的代码,并省略了相关的代码,即实际使用原子整数的代码?请阅读:可能重复的我没有使用任何原子整数。应显示所有相关代码。也许我的词汇课是相关的?参见编辑后的帖子。按照帖子的建议去做会让我产生StackOverFlowException@安德烈亚斯
public class JSONPoints extends MemoryPoints {
// Info on how to persist
private Gson gson;
private File file;
public JSONPoints() {
file = new File("directory", "points.json");
gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).create();
}
public Gson getGson() {
return gson;
}
public void setGson(Gson gson) {
this.gson = gson;
}
public void forceSave() {
forceSave(true);
}
public void forceSave(boolean sync) {
saveCore(file, this, sync);
}
private boolean saveCore(File target, MemoryPoints data, boolean sync) {
return DiscUtil.writeCatch(target, this.gson.toJson(data), sync);
}
public void load() {
MemoryPoints memoryPoints = this.loadCore();
if (memoryPoints == null) {
return;
}
this.points.clear();
this.points.putAll(memoryPoints.points);
}
private MemoryPoints loadCore() {
if (!this.file.exists()) {
return this;
}
String content = DiscUtil.readCatch(this.file);
if (content == null) {
return null;
}
MemoryPoints data = this.gson.fromJson(
content,
new TypeToken<MemoryPoints>() {
}.getType());
saveCore(this.file, data, true); // Update the flatfile
return data;
}
public class GLocation implements Serializable {
private transient static final long serialVersionUID = -6049901271320963314L;
private transient Location location = null;
private String worldName;
private double x;
private double y;
private double z;
private float pitch;
private float yaw;
public GLocation(Location loc) {
setLocation(loc);
}
public GLocation(String worldName, double x, double y, double z, float yaw, float pitch) {
this.worldName = worldName;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public GLocation(String worldName, double x, double y, double z) {
this(worldName, x, y, z, 0, 0);
}
// This returns the actual Location
public final Location getLocation() {
// Make sure Location is initialized before returning it
initLocation();
return location;
}
// Change the Location
public void setLocation(Location loc) {
this.location = loc;
this.worldName = loc.getWorld().getName();
this.x = loc.getX();
this.y = loc.getY();
this.z = loc.getZ();
this.yaw = loc.getYaw();
this.pitch = loc.getPitch();
}
// This initializes the Location
private void initLocation() {
// if location is already initialized, simply return
if (location != null) {
return;
}
// get World; hopefully it's initialized at this point
World world = Bukkit.getWorld(worldName);
if (world == null) {
return;
}
// store the Location for future calls, and pass it on
location = new Location(world, x, y, z, yaw, pitch);
}
public String getWorldName() {
return worldName;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
public double getPitch() {
return pitch;
}
public double getYaw() {
return yaw;
}