Closed desaikd closed 4 months ago
It would be nice if you could drop the generated code into a GitHub Gist or something so that a reviewer can also look at the generated code without having to check out and build the PR locally.
I added the generated code in the PR description for one of the schema files. But I will add Gists with generated code from now to make this easier.
The read and write code is exposing some things that are not very idiomatic Java. They don't need to be addressed in this PR, but I think they are things that must be addressed before saying that this is production-ready.
- The "new type" pattern—while this is idiomatic in Rust, it is potentially expensive and awkward to use in Java. I think that anonymous, parameterized-list types should not be wrapped in a new Java type.
What did you mean by new type
pattern. Did you mean just adding anonymous types into the same class as the one that uses it?
- We need to have a builder for classes that are based on Ion
struct
s.
Yes, builder needs to be added for sure. I have already created an issue for it and will work on it as the next PR. Reference: #97
- I think we should try to define anonymous types as nested static classes inside their respective parent type. E.g. using the schema given here, that would mean that
AnonymousType2
would actually beStructWithFields.AnonymousType2
.
Yes, I will change that.
I added the generated code in the PR description for one of the schema files.
I didn't even notice that... it's my fault for jumping straight into the code, I guess.
What did you mean by new type pattern.
https://doc.rust-lang.org/rust-by-example/generics/new_types.html
The Anonymous2
type is basically just a "new type" that wraps List<String>
.
What did you mean by new type pattern.
https://doc.rust-lang.org/rust-by-example/generics/new_types.html
The
Anonymous2
type is basically just a "new type" that wrapsList<String>
.
As per offline discussion, this will be added with a separate PR.
Issue #87:
Description of changes:
This PR adds read-write API generation support for Java.
Example generated APIs
This example uses schema
struct_with_fields
fromcode-gen-projects/schema/
. Note: The generated code has been formatted here and actual code might have extra lines and tabs.Complete generated code can be found here.
List of changes:
is_built_in_type
filter forJavaLanguage
to changefloat
todouble
and added Ion float field to verifyCodeGenTest.java
CodeGenTest.java
Test
Roundtrip tests are added to test generated read-write API. The test consists of 3 steps:
IonReader
into data model withreadFrom
APIIonWriter
as Ion withwriteTo
APIIonLoader
check equivalence of initially provided Ion data and the Ion data written bywriteTo
API.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.