palantir / palantir/conjure-java
A union type even in invalid format should deserialize to Unknown
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 39
- Forks
- 49
- Avg merge
- 8h 22m
- Merged PRs (30d)
- 32
Description
What happened?
Given:
objects:
Foo:
fields:
foo: string
Bar:
fields:
bar: string
FooBar:
union:
foo: Foo
bar: Bar
the following fails:
ObjectMapper mapper = ObjectMappers.createDefaultJsonObjectMapper(false);
String good = "{\n"
+ " \"type\" : \"bar\",\n"
+ " \"bar\" : {\n"
+ " \"bar\" : \"123\"\n"
+ " }\n"
+ "}";
String bad = "{\n"
+ " \"type\" : \"new\",\n"
+ " \"some-string\""
+ "}";
assertThat(mapper.readValue(good, FooBar.class))
.extracting("value")
.extracting("value")
.isInstanceOf(Bar.class);
assertThat(mapper.readValue(bad, FooBar.class))
.extracting("value")
.extracting(Object::getClass)
.extracting(Class::getSimpleName)
.asString()
.contains("UnknownWrapper");
What did you want to happen?
The test should pass.
We can achieve this by modifying the generated code for the unknown wrapper to look something like this:

this is obviously not completely correct since if type is missing or there exists no sub-object, we'd be setting the raw invalid json as type, so we'd probably have to do a little more work (like making type optional or nullable for the unknown wrapper)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated FooBar union and ObjectMappers.createDefaultJsonObjectMapper(false), then reproduce the good and bad JSON cases from the issue. Trace how the unknown wrapper is selected during deserialization; done means the bad payload yields UnknownWrapper while valid bar input still yields Bar, with coverage for missing type or sub-object behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100