Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 5ec8c00

Browse files
committed
Fix #23 for 2.6.4
1 parent d0792d9 commit 5ec8c00

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-dataformat-avro
44
= Releases
55
------------------------------------------------------------------------
66

7+
2.6.4 (not yet released)
8+
9+
#23: MapWriteContext.createChildObjectContext() should call _schema.getValueType()
10+
(reported by shoeree@github, cresny@github)
11+
712
2.6.3 (12-Oct-2015)
813
2.6.2 (15-Sep-2015)
914
2.6.1 (09-Aug-2015)

src/main/java/com/fasterxml/jackson/dataformat/avro/ser/MapWriteContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final AvroWriteContext createChildArrayContext() {
4646
public final AvroWriteContext createChildObjectContext() throws JsonMappingException
4747
{
4848
_verifyValueWrite();
49-
AvroWriteContext child = _createObjectContext(_schema.getElementType());
49+
AvroWriteContext child = _createObjectContext(_schema.getValueType());
5050
_data.put(_currentName, child.rawValue());
5151
return child;
5252
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.fasterxml.jackson.dataformat.avro;
2+
3+
import java.io.IOException;
4+
import java.util.Map;
5+
6+
import org.apache.avro.Schema;
7+
import org.junit.Test;
8+
9+
import com.fasterxml.jackson.annotation.JsonProperty;
10+
11+
import com.fasterxml.jackson.databind.ObjectMapper;
12+
13+
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
14+
import com.fasterxml.jackson.dataformat.avro.AvroSchema;
15+
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
16+
17+
public class NestedMapTest extends AvroTestBase
18+
{
19+
public static class Nester {
20+
@JsonProperty
21+
public Map<String,Map<String,Integer>> nested;
22+
}
23+
24+
public void testSerialization() throws IOException
25+
{
26+
Nester fromJson = new ObjectMapper().readValue(
27+
"{\"nested\": {\"map\":{\"value\":1}}}"
28+
, Nester.class);
29+
30+
AvroMapper mapper = new AvroMapper();
31+
//Generate schema from class
32+
AvroSchemaGenerator gen = new AvroSchemaGenerator();
33+
mapper.acceptJsonFormatVisitor(Nester.class, gen);
34+
Schema schema = gen.getGeneratedSchema().getAvroSchema();
35+
36+
//Serialize
37+
byte[] avroData = mapper.writer(new AvroSchema(schema))
38+
.writeValueAsBytes(fromJson);
39+
40+
//Deserialize
41+
Nester nester = mapper.readerFor(Nester.class)
42+
.with(new AvroSchema(schema))
43+
.readValue(avroData);
44+
int val = nester.nested.get("map").get("value");
45+
assertEquals(1, val);
46+
47+
}
48+
}

0 commit comments

Comments
 (0)