blob: 55d60b0180c97b0bf14b140367e4958bf2d153a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package com.fasterxml.jackson.databind.jsontype;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.testutil.NoCheckSubTypeValidator;
public class NoTypeInfoTest extends BaseMapTest
{
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
@JsonDeserialize(as=NoType.class)
static interface NoTypeInterface {
}
final static class NoType implements NoTypeInterface {
public int a = 3;
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testWithIdNone() throws Exception
{
final ObjectMapper mapper = jsonMapperBuilder()
.activateDefaultTyping(NoCheckSubTypeValidator.instance)
.build();
// serialize without type info
String json = mapper.writeValueAsString(new NoType());
assertEquals("{\"a\":3}", json);
// and deserialize successfully
NoTypeInterface bean = mapper.readValue("{\"a\":6}", NoTypeInterface.class);
assertNotNull(bean);
NoType impl = (NoType) bean;
assertEquals(6, impl.a);
}
}
|