public static byte[] encode(final Object obj) {
        if (obj == null) {
            return null;
        }
        final String json = toJson(obj, false);
        return json.getBytes(CHARSET_UTF8);
    }
@Test
    public void testEncode() {
        class Foo extends RemotingSerializable {
            Map<Long, String> map = new HashMap<>();

            Foo() {
                map.put(0L, "Test");
            }

            public Map<Long, String> getMap() {
                return map;
            }
        }
        Foo foo = new Foo();
        String invalid = new String(foo.encode(), Charset.defaultCharset());
        String valid = new String(foo.encode(SerializerFeature.BrowserCompatible, SerializerFeature.QuoteFieldNames,
             SerializerFeature.MapSortField), Charset.defaultCharset());

        Gson gson = new Gson();
        final TypeAdapter<JsonElement> strictAdapter = gson.getAdapter(JsonElement.class);
        try {
            strictAdapter.fromJson(invalid);
            Assert.fail("Should have thrown");
        } catch (IOException ignore) {
        }

        try {
            strictAdapter.fromJson(valid);
        } catch (IOException ignore) {
            Assert.fail("Should not throw");
        }
    }