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

Thrown an exception if a value is not within an Enum #346

Open
saidatta opened this issue Jan 8, 2016 · 4 comments
Open

Thrown an exception if a value is not within an Enum #346

saidatta opened this issue Jan 8, 2016 · 4 comments
Labels

Comments

@saidatta
Copy link

saidatta commented Jan 8, 2016

If there is an Enum

enum capital { Sacaremento, Austin }

and you are eventually calling the fromMap in MapperComplex.java. whille it is doing the conversion for that attribute (say, attribute(is of enum type Capital)). If it cannot find within that Capital enum, then can you detect it by triggering an exception?

Example, EnumValueNotFoundException(attribute:capital, message:"Entered XYZ is not a valid capital.")

@RichardHightower
Copy link
Contributor

Is this a question or a bug report? If a bug report, what is the proposed expected behavior and the behavior seen?

@saidatta
Copy link
Author

saidatta commented Jan 8, 2016

My apologies on being ambiguous.

It is a bug report.

Observed behavior(Context):
Expanding on the above example

Lets say you have a domainObject(Places) and the enum(Capital)

class Places{
...
Capital capital
... }

enum Capital {.. Sacaremento, Austin .. }

When I send the below Map

HashMap fieldsMap = { ..
"capital" : "XYZ"
..}

to convert it to a domainObject of type Places

The returned object will have the attribute's( capital) value as null (converted from HashMap's XYZ)

Bug Scenario

Places places = MapObjectConversion.fromMap(fieldsMap, Places.class, {})

After executing the above call, I will receive the Object Places with the attribute as null with no indication that it couldn't find the value XYZ.

  • Bug : Trigger an exception to provide an indication if the value is not found in the Enum

Bug Reason:
This becomes a problem when the mapping is utilized for validation purposes.
As it is silently substituting that attribute's value with null instead of demonstrating it found an invalid value.

Follow up question
Is it possible for the entire mapping process to complete and throw a list of exceptions that it has found(if any). Currently, stops the mapping process and throws the first exception?

  • Reason: In a validation context, we want to collect all invalid values within the HashMap

Thanks, Let me know if you need any further details.

@RichardHightower
Copy link
Contributor

Ok so you have two things here. A bug. I agree that if we can't parse it to an ENUM that we should throw an exception, and the other is a feature request. You will want to file a second issue for the feature request. I can't say when I will work on this. It gets done in spurts. But it should be an easy fix. I accept pull requests.

@saidatta
Copy link
Author

saidatta commented Jan 8, 2016

Sounds good. Ill create a pull request after I work on it. Thanks Richard.

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