You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@JsonAttribute(ignore = true) is ignored for fields in kotlin classes #158
It would be great if there was a Kotlin test project where such examples could be tested and verified but I have not yet found to setup such a project via Maven.
I guess I could set it up via gradle, but I'd much prefer to have it in Maven so all tests can run at once.
Anyway, can you write relevant Java class like this:
and make a PR which shows the issue (there is some generated code which shows the exact Java output for the Kotlin model, thats how I extracted those examples).
I can take a look then on how to resolve it [although it's possible you'll figure out how to resolve it when you write such a test :) ]
Thank you for your answer. I tried to import maven project - tests-java8, and created a kotlin test in it, to run it, I have to add these lines to pom.xml:
packagecom.dslplatform.jsonimportcom.dslplatform.json.runtime.Settingsimportorg.junit.Assertimportorg.junit.Testimportjava.io.ByteArrayOutputStreamclassKotlinClassesTest{
val dslJson =DslJson(Settings.withRuntime<Any>().includeServiceLoader().allowArrayFormat(true))
@Test
fun`Field with JsonAttribute(ignore = true) flag, must not be included to result string`() {
val model =AKotlinModel("someStr", true)
model.stringFieldWithIgnoreFlag ="this string is ignored"
model.stringWhichShouldBeInPlace ="this string should be in json"val os =ByteArrayOutputStream()
dslJson.serialize(model, os)
Assert.assertEquals("{\"someString\" : \"someStr\", \"stringWhichShouldBeInPlace\" : \"this string should be in json\"}", os.toString())
}
}
This test is red for now with this output:
org.junit.ComparisonFailure:
Expected :{"someString" : "someStr", "stringWhichShouldBeInPlace" : "this string should be in json"}
Actual :{"stringFieldWithIgnoreFlag":"this string is ignored","paramWithIgnoreFlag":true}
And I have no idea, why my output JSON string has some of the fields and doesn't have others. Any thoughts on how to deal with it?
I tried setting up java8 test project like that but it didn't do annotation processing on Kotlin at all.
So I setup a separate project which is somewhat better but still fails to compile for some probably trivial reasons (it creates output in generated-sources instead of generated-test-sources)
If you can help out with fixing that project so it starts compiling that would be great: 2db2de5
As for the ignore thing, DSL-JSON still does not support defaults on arguments, although you can simulate that with empty ctors in which case defaults are preserved. The model you provided for tests is missing those defaults so it doesn't compile, but I'll look whats going on when test project starts running.
Activity
zapov commentedon Jan 18, 2020
It would be great if there was a Kotlin test project where such examples could be tested and verified but I have not yet found to setup such a project via Maven.
I guess I could set it up via gradle, but I'd much prefer to have it in Maven so all tests can run at once.
Anyway, can you write relevant Java class like this:
dsl-json/tests-java8/src/test/java/com/dslplatform/json/JsonObjectTest.java
Line 70 in 8783d39
I can take a look then on how to resolve it [although it's possible you'll figure out how to resolve it when you write such a test :) ]
runaloop commentedon Jan 20, 2020
Thank you for your answer. I tried to import maven project - tests-java8, and created a kotlin test in it, to run it, I have to add these lines to pom.xml:
Kotlin class looks like:
And Kotlin test looks like:
This test is red for now with this output:
And I have no idea, why my output JSON string has some of the fields and doesn't have others. Any thoughts on how to deal with it?
zapov commentedon Feb 17, 2020
I tried setting up java8 test project like that but it didn't do annotation processing on Kotlin at all.
So I setup a separate project which is somewhat better but still fails to compile for some probably trivial reasons (it creates output in generated-sources instead of generated-test-sources)
If you can help out with fixing that project so it starts compiling that would be great:
2db2de5
As for the ignore thing, DSL-JSON still does not support defaults on arguments, although you can simulate that with empty ctors in which case defaults are preserved. The model you provided for tests is missing those defaults so it doesn't compile, but I'll look whats going on when test project starts running.
zapov commentedon Oct 8, 2020
FWIW this test is now in, although commented out: https://github.com/ngs-doo/dsl-json/blob/master/tests-kotlin/src/main/kotlin/com/dslplatform/json/ModelWithIgnore.kt#L17
I have some questions though: