Skip to content

Commit

Permalink
#281: Since 2.13, UnsupportedOperationException is thrown instead o…
Browse files Browse the repository at this point in the history
…f `InvalidDefinitionException`. Reason in 2.13 in that `ToEmptyObjectSerializer` is used to serialize `java.util.Map` which calls `visitor.expectObjectFormat(typeHint)` and thus different exception is thrown at the end and when schema is requested from mapper. (#282)

Co-authored-by: Michal Foksa <Michal.Foksa@external.t-mobile.at>
  • Loading branch information
MichalFoksa and Michal Foksa authored May 26, 2021
1 parent 79f9215 commit c94dbef
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static class RootType
{
@JsonAlias({"nm", "Name"})
public String name;

public int value;

List<String> other;
}

Expand Down Expand Up @@ -51,7 +51,7 @@ public ByteBuffer getBytes() {
}
}
}

/*
/**********************************************************
/* Tests
Expand Down Expand Up @@ -94,21 +94,21 @@ public void testEmployee() throws Exception
AvroSchema schema = gen.getGeneratedSchema();
assertNotNull(schema);

String json = schema.getAvroSchema().toString(true);
String json = schema.getAvroSchema().toString(true);
assertNotNull(json);
AvroSchema s2 = MAPPER.schemaFrom(json);
assertNotNull(s2);

Employee empl = new Employee();
empl.name = "Bobbee";
empl.age = 39;
empl.emails = new String[] { "bob@aol.com", "bobby@gmail.com" };
empl.boss = null;

// So far so good: try producing actual Avro data...
byte[] bytes = MAPPER.writer(schema).writeValueAsBytes(empl);
assertNotNull(bytes);

// and bring it back, too
Employee e2 = getMapper().readerFor(Employee.class)
.with(schema)
Expand All @@ -131,7 +131,7 @@ public void testMap() throws Exception
assertNotNull(s2);

// should probably verify, maybe... ?

// System.out.println("Map schema:\n"+json);
}

Expand Down Expand Up @@ -165,10 +165,8 @@ public void testSchemaForUntypedMap() throws Exception
try {
MAPPER.schemaFor(Map.class);
fail("Not expected to work yet");
} catch (InvalidDefinitionException e) {
verifyException(e, "\"Any\" type");
verifyException(e, "not supported");
verifyException(e, "`java.lang.Object`");
} catch (UnsupportedOperationException e) {
verifyException(e, "Maps with non-stringable keys are not supported yet");
}
}
}

0 comments on commit c94dbef

Please sign in to comment.