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

How to pass values to GenericStringRandomizer with @Randomizer annotation #299

Closed
abg-dev opened this issue Mar 22, 2018 · 2 comments
Closed
Labels
Milestone

Comments

@abg-dev
Copy link

abg-dev commented Mar 22, 2018

Thanks for the great work! I really liked this library and planning to use in our project. One question I had was, how to correctly write the following with RandomizerArgument annotation:

// GenericStringRandomizer takes a String [] as argument...
@Randomizer(value = GenericStringRandomizer.class, args = { 
			@RandomizerArgument(value = "Jhon, Doe", type = String[].class) // this is surely not the correct way
})
String firstName;

This does not work ofcourse and says Caused by:

com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String[] out of VALUE_STRING token . 

I was wondering how to pass a textual representation of String array... any clue?

fmbenhassine added a commit that referenced this issue Jan 15, 2019
Jackson is able to convert an array of String values to an
array of other Java types. However, it does not parse a raw
String and split it if it is intended to be mapped to an array.

This commit prepares the data for Jackson by splitting the
value of `RandomizerArgument` when its type is an array.

NB: The goal is to cover simple use cases of comma separated
values like reported in #299. There is no plan to make this
feature support custom separator, date format, number format, etc.
@fmbenhassine
Copy link
Member

Hi @ashbike ,

Thank you for reporting this issue. It is indeed a bug in RB. I pushed a fix in version 3.8.0-SNAPSHOT. Can you give it a try and let me know if it is ok for you? You can use the same syntax as in your example and it should work fine now (cda1de5 contains a similar example I used to test the fix).

You will need to add sonatype's snapshot repository to be able to import the snapshot version of RB.

Kr,
Mahmoud

@fmbenhassine fmbenhassine added this to the v3.8.0 milestone Jan 15, 2019
@fmbenhassine
Copy link
Member

I'm closing this issue, the fix will be part of the upcoming v3.8 release.

@ashbike Please consider giving your feedback with the released version, if you still have any problem, please re-open this issue. Thank you for reporting this out!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants