Been a few months since i got stuck. The scenario i am in. A client want X ammount of a class. So basically 5 instances of a dog. Dog has sets of properties, hashmaps etc. How would i send that back efficiently?
The main class is:
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package altarianonline.model.Pets;
import altarianonline.model.Buff1.Buffs;
import altarianonline.model.Character.CharacterProperty;
import altarianonline.model.Interfaces.Item;
import altarianonline.model.Interfaces.Pet;
import altarianonline.model.Interfaces.Skill;
import altarianonline.model.Interfaces.Skin;
import com.smartfoxserver.v2.protocol.serialization.SerializableSFSType;
import java.util.Map;
public class RpgPet implements SerializableSFSType
{
private static final String TAB = "\t";
private static final String NEW_LINE = "\n";
private String name;
private String type;
private int skin;
private Double x;
private Double y;
private Double z;
private Double rot;
private Map<String, PetProperty> MainCompose;
private Map<String, PetProperty> SubCompose;
private Map<String, PetProperty> IniCompose;
private Map<String, Skill> skills;
private Map<String, Buffs> buff;
public RpgPet()
{
// TODO Auto-generated constructor stub
}
public RpgPet(String name, String type, int skin, Double x, Double y, Double z, Double rot)
{
this.name = name;
this.type = type;
this.skin = skin;
this.x = x;
this.y = y;
this.z = z;
this.rot = rot;
}
public Double getX()
{
return x;
}
public void setX(Double x)
{
this.x = x;
}
public Double getY()
{
return y;
}
public void setY(Double y)
{
this.y = y;
}
public Double getZ()
{
return z;
}
public void setZ(Double z)
{
this.z = z;
}
public Double getRot()
{
return rot;
}
public void setRot(Double rot)
{
this.rot = rot;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
public int getSkin()
{
return skin;
}
public void setSkin(int skin)
{
this.skin = skin;
}
public Map<String, Buffs> getBuff()
{
return buff;
}
public void setBuff(Map<String, Buffs> buff)
{
this.buff = buff;
}
public Map<String, PetProperty> getMainCompose()
{
return MainCompose;
}
public void setMainCompose(Map<String, PetProperty> maincompose)
{
this.MainCompose = maincompose;
}
public Map<String, PetProperty> getSubCompose()
{
return SubCompose;
}
public void getSubCompose(Map<String, PetProperty> subcompose)
{
this.SubCompose = subcompose;
}
public Map<String, PetProperty> getIniCompose()
{
return IniCompose;
}
public void getIniCompose(Map<String, PetProperty> inicompose)
{
this.IniCompose = inicompose;
}
public Map<String, Skill> getSkills()
{
return skills;
}
public void setSkills(Map<String, Skill> skills)
{
this.skills = skills;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(NEW_LINE);
sb.append("+------------------------------------+").append(NEW_LINE);
sb.append(" Pet: ").append(name).append(NEW_LINE);
sb.append(TAB).append("Type: ").append(type).append(NEW_LINE);
sb.append(TAB).append("Location: ").append(x).append(" , ").append(y).append(" , ").append(z).append(" Rotation: ").append(rot).append(NEW_LINE);
sb.append("+------------------------------------+").append(NEW_LINE);
sb.append(TAB).append("Spells: ").append(NEW_LINE);
if (skills != null)
for (Map.Entry<String, Skill> entry : skills.entrySet())
sb.append(TAB).append(TAB).append(entry.getValue().getId()).append(" -- Modifies: ").append(entry.getValue().getModifies()).append(", Level: ").append(entry.getValue().getLevel()).append(NEW_LINE);
sb.append(TAB).append("Main Compose: ").append(NEW_LINE);
if (MainCompose != null)
for (Map.Entry<String, PetProperty> entry : MainCompose.entrySet())
sb.append(TAB).append(TAB).append(entry.getKey()).append(" -- ").append(entry.getValue()).append(NEW_LINE);
sb.append(TAB).append("Sub Compose: ").append(NEW_LINE);
if (SubCompose != null)
for (Map.Entry<String, PetProperty> entry : SubCompose.entrySet())
sb.append(TAB).append(TAB).append(entry.getKey()).append(" -- ").append(entry.getValue()).append(NEW_LINE);
sb.append(TAB).append("Buffs: ").append(NEW_LINE);
if (buff != null)
for (Map.Entry<String, Buffs> entry : buff.entrySet())
sb.append(TAB).append(TAB).append(entry.getKey()).append(" Name: ").append(entry.getValue().getName()).append(" Type:").append(entry.getValue().getType()).append(" Duration:").append(entry.getValue().getDuration()).append(" Level:").append(entry.getValue().getLevel()).append(" Owner:").append(entry.getValue().getOwner()).append(" Percent:").append(entry.getValue().getPct()).append(" Id:").append(entry.getValue().getId()).append(NEW_LINE);
return sb.toString();
}
}
Which is built up from the Pet Properties.
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package altarianonline.model.Pets;
import com.smartfoxserver.v2.protocol.serialization.SerializableSFSType;
public class PetProperty implements SerializableSFSType
{
private int value;
private String id;
public PetProperty()
{
// TODO Auto-generated constructor stub
}
public PetProperty(int value, String id)
{
this.value = value;
this.id = id;
}
public int getValue()
{
return value;
}
public void setValue(int value)
{
this.value = value;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
@Override
public String toString()
{
return "value: " + value;
}
}
At which im trying to use a server handler which is this code:
Code: Select all
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package altarianonline.model.Pets;
import com.smartfoxserver.v2.protocol.serialization.SerializableSFSType;
public class PetProperty implements SerializableSFSType
{
private int value;
private String id;
public PetProperty()
{
// TODO Auto-generated constructor stub
}
public PetProperty(int value, String id)
{
this.value = value;
this.id = id;
}
public int getValue()
{
return value;
}
public void setValue(int value)
{
this.value = value;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
@Override
public String toString()
{
return "value: " + value;
}
}
However is generates
11:21:27,610 INFO [SFSWorker:Ext:2] Extensions - {altExt}: finding pets
11:21:27,615 WARN [SFSWorker:Ext:2] protocol.SFSIoHandler - com.smartfoxserver.v2.exceptions.SFSRuntimeException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: java.lang.IllegalStateException: Cannot serialize object: {}, type: java.util.HashMap -- It doesn't implement the SerializableSFSType interface
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.pojo2sfs(DefaultSFSDataSerializer.java:1461)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:852)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.arr2bin(DefaultSFSDataSerializer.java:563)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.array2binary(DefaultSFSDataSerializer.java:549)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:843)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.obj2bin(DefaultSFSDataSerializer.java:519)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.object2binary(DefaultSFSDataSerializer.java:502)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:848)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.obj2bin(DefaultSFSDataSerializer.java:519)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.object2binary(DefaultSFSDataSerializer.java:502)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.encodeObject(DefaultSFSDataSerializer.java:848)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.obj2bin(DefaultSFSDataSerializer.java:519)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.object2binary(DefaultSFSDataSerializer.java:502)
com.smartfoxserver.v2.entities.data.SFSObject.toBinary(SFSObject.java:234)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler.handleWrite(BinaryIoHandler.java:84)
com.smartfoxserver.v2.protocol.SFSIoHandler.onDataWrite(SFSIoHandler.java:223)
com.smartfoxserver.v2.protocol.SFSProtocolCodec.onPacketWrite(SFSProtocolCodec.java:165)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.writeToSocket(BitSwarmEngine.java:412)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.write(BitSwarmEngine.java:406)
com.smartfoxserver.bitswarm.io.Response.write(Response.java:71)
com.smartfoxserver.v2.api.response.SFSResponseApi.sendExtResponse(SFSResponseApi.java:91)
com.smartfoxserver.v2.api.SFSApi.sendExtensionResponse(SFSApi.java:1515)
com.smartfoxserver.v2.extensions.BaseSFSExtension.send(BaseSFSExtension.java:487)
com.smartfoxserver.v2.extensions.BaseSFSExtension.send(BaseSFSExtension.java:462)
com.smartfoxserver.v2.extensions.BaseClientRequestHandler.send(BaseClientRequestHandler.java:56)
altarianonline.GetPets.handleClientRequest(GetPets.java:132)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:208)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController.processRequest(ExtensionReqController.java:174)
com.smartfoxserver.v2.controllers.v290.ExtensionReqController$1.run(ExtensionReqController.java:68)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Which im assuming its because i am sending back a Hashmap not directly the class as i need to send multiple instances...soo any ideas ? Appreciated as always too!