Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic paramter conversion #175

Closed
wants to merge 2 commits into from
Closed

Automatic paramter conversion #175

wants to merge 2 commits into from

Conversation

Sprokof
Copy link

@Sprokof Sprokof commented Aug 12, 2024

Hi, I impl automatic convertion to class in params, it's optional functionality in @JsonSource, but not in @JsonFileSource, tests also was rewrote. (Related to #30 issue). Hope this changes will be useful for you.

@Sprokof
Copy link
Author

Sprokof commented Aug 12, 2024

My mistake, fix it in during today

Copy link
Owner

@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you talk a bit about how this might impact existing users of this library?
Perhaps this might make sense implemented as a second provider that targets objects instead of augmenting the existing provider.

I'd like to keep this open for feedback from anyone using this (as I'm not actively doing so right now). I'm very out of the loop when it comes to how to publish Java libs these days.

You're also welcome to fork this and release it under the same name (in your own namespace). That might be best as I can't even recall what's necessary to release this at this point (and I see that the CI automation is failing).

@@ -34,6 +34,7 @@ dependencies {
// jakarta.json-api is not exposed on any public members, so does not need
// to be exposed to use the library
implementation 'jakarta.json:jakarta.json-api:2.1.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.0'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a jakarta lib that would work for this rather than jackson? (and is that a reasonable idea)
Possibly this: https://projects.eclipse.org/projects/ee4j.jsonb

The general goal of this library was to avoid taking a dependency on any specific JSON api, and I think at the time the jakarta ones were the closest to being a general spec. It's possible that jackson is more widely used, but it's been a long while since I've written any Java or looked at this library. You probably have more up to date context about these things than I do currently (or could perhaps dig into this to understand whether this is the right approach).

@@ -1,7 +1,7 @@
# junit-json-params

A [Junit 5](http://junit.org/junit5/) library to provide annotations that load
data from JSON Strings or files in parameterized tests.
singleObject from JSON Strings or files in parameterized tests.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "data as either values or deserialized into a a single object" would make more sense (If you're not a native English speaker, slap this doc into an LLM and check what makes sense there.)

}
}

private static Stream<JsonValue> values(Reader reader) {
private static Stream<JsonValue> values(Reader reader, boolean arrayClass) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this.isArrayClass directly in this method rather than calling a private method with value which is stored in the class.

Comment on lines +58 to +62
Stream<JsonValue> values = Stream.of(structure);
if (structure.getValueType() == JsonValue.ValueType.ARRAY) {
values = arrayClass ? values : structure.asJsonArray().stream();
}
return values;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is possibly simplified as:

bool isArray = (structure.getValueType() == JsonValue.ValueType.ARRAY);
return (isArray && !this.isArrayClass)
  ? structure.asJsonArray().stream
  : Stream.of(structure);

Does that make sense? That avoids calling Stream.of unless it's needed. It's unlikely this is a perf issue, but I think it's clearer. Thoughts?


public class JsonConverter implements ArgumentConverter {
private static final Logger logger = Logger.getLogger(JsonConverter.class.getSimpleName());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the impact of adding logging to the tests? Does it get in the way of the output / cause any problems?

I suspect that it might be worth removing this to avoid problems with code that also logs. (But again, it's been a while since I looked at Java and can't recall where J.u.l fits in to things).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at how the tests change, it seems like this change would break any code that uses this library. Is that right?

Would it be worth making this change as an additive approach instead of one that replaces the implementation? This would make it easier for existing projects to continue to use this library as it is and newer ones to use the object approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you are right

@Sprokof
Copy link
Author

Sprokof commented Aug 13, 2024

Hi again, I think will good to remove that code and add just second converter, example JsonPojoConverter, to map JsonObject to pojo, what do you think?

@joshka
Copy link
Owner

joshka commented Aug 13, 2024

Hi again, I think will good to remove that code and add just second converter, example JsonPojoConverter, to map JsonObject to pojo, what do you think?

Sounds good, but see my comment about making a fork of this repo to continue work on. I'd recommend taking that approach (and seeing if you can find some other users of this tood). I'm happy to point others towards your fork, but I'd prefer not to hand over this project to an unknown person(due to the stuff that happened with xz a while back)

@Sprokof
Copy link
Author

Sprokof commented Aug 13, 2024

I agree with all, lets close PR

@Sprokof Sprokof closed this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants