|
| 1 | +package com.fasterxml.jackson.dataformat.protobuf.schema; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertArrayEquals; |
| 4 | + |
| 5 | +import org.junit.Ignore; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper; |
| 8 | +import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase; |
| 9 | + |
| 10 | +public class SchemaWithIntArray483Test extends ProtobufTestBase |
| 11 | +{ |
| 12 | + static class IntArrayBean |
| 13 | + { |
| 14 | +// @JsonProperty(required = true, index = 1) |
| 15 | + public int[] value; |
| 16 | + } |
| 17 | + |
| 18 | + /* |
| 19 | + /********************************************************** |
| 20 | + /* Test methods |
| 21 | + /********************************************************** |
| 22 | + */ |
| 23 | + |
| 24 | + private final ProtobufMapper MAPPER = new ProtobufMapper(); |
| 25 | + |
| 26 | + // [dataformats-binary#483]: int arrays supported as nested (property) values |
| 27 | + public void testWithWrappedIntArray() throws Exception |
| 28 | + { |
| 29 | + ProtobufSchema schema = MAPPER.generateSchemaFor(IntArrayBean.class); |
| 30 | + assertNotNull(schema); |
| 31 | + |
| 32 | + IntArrayBean input = new IntArrayBean(); |
| 33 | + input.value = new int[] { 1, 2, 3 }; |
| 34 | + |
| 35 | + byte[] proto = MAPPER.writer().with(schema) |
| 36 | + .writeValueAsBytes(input); |
| 37 | + IntArrayBean result = MAPPER.readerFor(IntArrayBean.class) |
| 38 | + .with(schema) |
| 39 | + .readValue(proto); |
| 40 | + assertNotNull(result.value); |
| 41 | + assertArrayEquals(input.value, result.value); |
| 42 | + } |
| 43 | + |
| 44 | + // [dataformats-binary#483]: cannot support root-level arrays, unfortunately |
| 45 | + @Ignore("Can't be supported with Protobuf") |
| 46 | + public void dontTestWithRootIntArray() throws Exception |
| 47 | + { |
| 48 | + ProtobufSchema schema = MAPPER.generateSchemaFor(int[].class); |
| 49 | + assertNotNull(schema); |
| 50 | + |
| 51 | + int[] input = new int[] { 1, 2, 3 }; |
| 52 | + |
| 53 | + byte[] proto = MAPPER.writer().with(schema) |
| 54 | + .writeValueAsBytes(input); |
| 55 | + int[] result = MAPPER.readerFor(int[].class) |
| 56 | + .with(schema) |
| 57 | + .readValue(proto); |
| 58 | + assertNotNull(result); |
| 59 | + assertArrayEquals(input, result); |
| 60 | + } |
| 61 | +} |
0 commit comments