You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomJSONSerializerTest.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.vaadin.server;
  2. import static org.junit.Assert.assertTrue;
  3. import java.lang.reflect.Type;
  4. import org.junit.Test;
  5. import com.vaadin.server.communication.JSONSerializer;
  6. import com.vaadin.ui.ConnectorTracker;
  7. import elemental.json.JsonValue;
  8. public class CustomJSONSerializerTest {
  9. public static class Foo {
  10. }
  11. public static class FooSerializer implements JSONSerializer<Foo> {
  12. @Override
  13. public Foo deserialize(Type type, JsonValue jsonValue,
  14. ConnectorTracker connectorTracker) {
  15. return null;
  16. }
  17. @Override
  18. public JsonValue serialize(Foo value,
  19. ConnectorTracker connectorTracker) {
  20. return null;
  21. }
  22. }
  23. @Test
  24. public void testMultipleRegistration() {
  25. boolean thrown = false;
  26. try {
  27. JsonCodec.setCustomSerializer(Foo.class, new FooSerializer());
  28. JsonCodec.setCustomSerializer(Foo.class, new FooSerializer());
  29. } catch (IllegalStateException ise) {
  30. thrown = true;
  31. } finally {
  32. JsonCodec.setCustomSerializer(Foo.class, null);
  33. }
  34. assertTrue("Multiple serializer registrations for one class "
  35. + "should throw an IllegalStateException", thrown);
  36. }
  37. }