Search in sources :

Example 1 with EntityChangedEvent

use of org.summerb.easycrud.api.dto.EntityChangedEvent in project summerb by skarpushin.

the class EntityChangedEventAdapter method deserialize.

@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public EntityChangedEvent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    Class<? extends DtoBase> klass = resolveParametersClass(jsonObject);
    JsonElement jsonElement = jsonObject.get(INSTANCE);
    DtoBase value = context.deserialize(jsonElement, klass);
    ChangeType changeType = context.deserialize(jsonObject.get("ct"), ChangeType.class);
    return new EntityChangedEvent(value, changeType);
}
Also used : DtoBase(org.summerb.utils.DtoBase) ChangeType(org.summerb.easycrud.api.dto.EntityChangedEvent.ChangeType) EntityChangedEvent(org.summerb.easycrud.api.dto.EntityChangedEvent) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 2 with EntityChangedEvent

use of org.summerb.easycrud.api.dto.EntityChangedEvent in project summerb by skarpushin.

the class EntityChangedEventAdapterTest method testDeserializeExpectOkForAllowedClass.

@SuppressWarnings("rawtypes")
@Test
public void testDeserializeExpectOkForAllowedClass() {
    Gson gson = getFixture();
    EntityChangedEvent evt = gson.fromJson("{\"ct\": \"asdasd\", \"vt\": \"org.summerb.easycrud.api.dto.tools.TestDto\", \"v\": {\"email\": \"asd\"}}", EntityChangedEvent.class);
    assertNotNull(evt);
    assertEquals("asd", ((TestDto) evt.getValue()).getEmail());
}
Also used : EntityChangedEvent(org.summerb.easycrud.api.dto.EntityChangedEvent) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 3 with EntityChangedEvent

use of org.summerb.easycrud.api.dto.EntityChangedEvent in project summerb by skarpushin.

the class EntityChangedEventAdapterTest method testDeserializeExpectExceptionForNotAllowedClass.

@Test(expected = IllegalArgumentException.class)
@SuppressWarnings({ "rawtypes", "unused" })
public void testDeserializeExpectExceptionForNotAllowedClass() {
    Gson gson = getFixture();
    EntityChangedEvent evt = gson.fromJson("{\"ct\": \"asdasd\", \"vt\": \"javax.print.event.PrintEvent\", \"v\": {\"source\": \"asd\"}}", EntityChangedEvent.class);
    fail("We should be dead by now");
}
Also used : EntityChangedEvent(org.summerb.easycrud.api.dto.EntityChangedEvent) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

EntityChangedEvent (org.summerb.easycrud.api.dto.EntityChangedEvent)3 Gson (com.google.gson.Gson)2 Test (org.junit.Test)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ChangeType (org.summerb.easycrud.api.dto.EntityChangedEvent.ChangeType)1 DtoBase (org.summerb.utils.DtoBase)1