Comments (3)
Please include actual code you are using: textual description is not enough to know what is being attempted.
Note, though, that the exception comes from Apache Avro library which does validation for generated schema.
from jackson-dataformats-binary.
Hi, @cowtowncoder , here is the reproductible example,
it seems the reproduction behaviour, is more linked to the JsonValue annotation,
when commenting this annotation, this work, and fail if the annotation is present
import java.util.HashMap;
import java.util.Map;
import javax.annotation.processing.Generated;
import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
import com.fasterxml.jackson.dataformat.avro.jsr310.AvroJavaTimeModule;
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
/**
* class to reproduce an avro error, for jackson databind
*/
public class GenerateAvroError {
@Generated("jsonschema2pojo")
public enum EnumTypeContrat {
CARD_S("CARD-S"),
CARD_ELD("CARD-ELD"),
GRD_F("GRD-F"),
CSD("CSD"),
GRD_RE("GRD-RE"),
PROTOC_501("PROTOC-501"),
CRAE("CRAE"),
CARD_I("CARD-I"),
CSD_I("CSD-I");
private final String value;
private final static Map<String, EnumTypeContrat> CONSTANTS = new HashMap<String,EnumTypeContrat>();
static {
for (EnumTypeContrat c: values()) {
CONSTANTS.put(c.value, c);
}
}
EnumTypeContrat(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
@JsonValue
public String value() {
return this.value;
}
@JsonCreator
public static EnumTypeContrat fromValue(String value) {
EnumTypeContrat constant = CONSTANTS.get(value);
if (constant == null) {
throw new IllegalArgumentException(value);
} else {
return constant;
}
}
}
public static class DummyClassToReproduceError {
private EnumTypeContrat contract;
@JsonProperty("contr")
public EnumTypeContrat getContract() {
return contract;
}
}
@Test
public void testSerializeAvro() throws Exception {
AvroSchemaGenerator gen = new AvroSchemaGenerator();
AvroMapper avroMapper = AvroMapper.builder().disable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.addModule(new AvroJavaTimeModule()).build();
gen.enableLogicalTypes();
avroMapper.acceptJsonFormatVisitor(DummyClassToReproduceError.class, gen);
com.fasterxml.jackson.dataformat.avro.AvroSchema schemaWrapper = gen.getGeneratedSchema();
org.apache.avro.Schema avroSchema = schemaWrapper.getAvroSchema();
String avroSchemaInJSON = avroSchema.toString(true);
System.out.println(avroSchemaInJSON);
}
}
the associated backtrace :
org.apache.avro.SchemaParseException: Illegal character in: CARD-S
at org.apache.avro.Schema.validateName(Schema.java:1566)
at org.apache.avro.Schema.access$400(Schema.java:91)
at org.apache.avro.Schema$EnumSchema.<init>(Schema.java:1035)
at org.apache.avro.Schema.createEnum(Schema.java:227)
at com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaHelper.createEnumSchema(AvroSchemaHelper.java:272)
at com.fasterxml.jackson.dataformat.avro.schema.StringVisitor.builtAvroSchema(StringVisitor.java:54)
at com.fasterxml.jackson.dataformat.avro.schema.VisitorFormatWrapperImpl.getAvroSchema(VisitorFormatWrapperImpl.java:103)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.schemaFieldForWriter(RecordVisitor.java:175)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.optionalProperty(RecordVisitor.java:117)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:843)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:914)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:565)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4670)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4649)
at xxxxxx.testSerializeAvro(GenerateAvroError.java:92)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
from jackson-dataformats-binary.
Thank you @pfr-enedis for the reproduction.
Yes, you are probably right wrt @JsonValue
.
from jackson-dataformats-binary.
Related Issues (20)
- Unexpected NullPointerException in `CBORParser`
- Unexpected `NullPointerException` in `ProtobufParser.currentName()`
- `ProtobufParser.currentName()` returns wrong value at root level
- Unexpected `ArrayIndexOutOfBoundsException` in `CBORParser` for corrupt String value
- IonReader.newBytes() throwing `NegativeArraySizeException` HOT 1
- `IonReader` throws `AssertionError` for Timestamp value HOT 1
- `IonReader.next()` throws `ArrayIndexOutOfBoundsException` for some corrupt content HOT 4
- Support for `StreamReadConstraints.maxNameLength` validation for CBOR, Smile backends
- Protobuf `LocalDateTime` serialization as Root value throws `UnsupportedOperationException` HOT 5
- Upgrade `ion-java` to latest (1.11.4)
- Upgrade `ion-java` to latest (1.11.7)
- ION deserialization type change from Double to Float in 2.17.0 HOT 7
- ION - MappingIterator skip the first line HOT 8
- Avro Schema generation: allow mapping Java Enum properties to Avro String values HOT 7
- Issue in Smile shared string values due to avoiding 0xFE and 0xFF HOT 6
- Failed copy(): `IonValueMapper` does not override copy() HOT 5
- [AVRO] 2 fields in schema for single property when getter and setter contain property name in capitals. HOT 3
- Upgrade `ion-java` dependency to 1.11.8
- Cannot deserialize `UUID` values HOT 8
- IonValueMapper.builder() not implemented, does not register modules HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-dataformats-binary.