/** * Test serialization code of RPClass by serializing it and then deserializing the stream again * and checking that it is the same RPClass. * * @throws IOException */ @Test public void testSerialization() throws IOException { RPClass expected = new RPClass("RPClassTest::I"); assertEquals(expected, RPClass.getRPClass("RPClassTest::I")); expected.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); expected.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.HIDDEN); expected.add( DefinitionClass.ATTRIBUTE, "c", Type.STRING, (byte) (Definition.PRIVATE | Definition.VOLATILE)); expected.add(DefinitionClass.RPSLOT, "d", 1, Definition.HIDDEN); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputSerializer os = new OutputSerializer(out); os.write(expected); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); InputSerializer is = new InputSerializer(in); RPClass result = (RPClass) is.readObject(new RPClass()); assertEquals(expected, result); }
@Override public void writeToJson(StringBuilder out) { super.writeToJson(out); out.append(","); OutputSerializer.writeJson(out, "username", username); out.append(",\"reason\": {"); OutputSerializer.writeJson(out, "code", Integer.toString(reason.ordinal())); out.append(","); OutputSerializer.writeJson(out, "name", reason.name()); out.append(","); OutputSerializer.writeJson(out, "text", reason.getText()); out.append("}"); }
@Override public void writeObject(marauroa.common.net.OutputSerializer out) throws IOException { super.writeObject(out); out.write((byte) reason.ordinal()); }