Skip to content

Commit

Permalink
Add test to show issue wrt #483
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 23, 2024
1 parent d61c086 commit 9e27d43
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.fasterxml.jackson.dataformat.protobuf.schema;

import static org.junit.Assert.assertArrayEquals;

import org.junit.Ignore;

import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;

public class SchemaWithIntArray483Test extends ProtobufTestBase
{
static class IntArrayBean
{
// @JsonProperty(required = true, index = 1)
public int[] value;
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ProtobufMapper MAPPER = new ProtobufMapper();

// [dataformats-binary#483]: int arrays supported as nested (property) values
public void testWithWrappedIntArray() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(IntArrayBean.class);
assertNotNull(schema);

IntArrayBean input = new IntArrayBean();
input.value = new int[] { 1, 2, 3 };

byte[] proto = MAPPER.writer().with(schema)
.writeValueAsBytes(input);
IntArrayBean result = MAPPER.readerFor(IntArrayBean.class)
.with(schema)
.readValue(proto);
assertNotNull(result.value);
assertArrayEquals(input.value, result.value);
}

// [dataformats-binary#483]: cannot support root-level arrays, unfortunately
@Ignore("Can't be supported with Protobuf")
public void dontTestWithRootIntArray() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(int[].class);
assertNotNull(schema);

int[] input = new int[] { 1, 2, 3 };

byte[] proto = MAPPER.writer().with(schema)
.writeValueAsBytes(input);
int[] result = MAPPER.readerFor(int[].class)
.with(schema)
.readValue(proto);
assertNotNull(result);
assertArrayEquals(input, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static class BinaryBean
/**********************************************************
*/

final ProtobufMapper MAPPER = new ProtobufMapper();
private final ProtobufMapper MAPPER = new ProtobufMapper();

// [dataformats-binary#68]
public void testWithUUID() throws Exception
Expand Down

0 comments on commit 9e27d43

Please sign in to comment.