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

Add a SimpleToString option #82

Closed
mattrpav opened this issue May 18, 2017 · 8 comments
Closed

Add a SimpleToString option #82

mattrpav opened this issue May 18, 2017 · 8 comments

Comments

@mattrpav
Copy link
Collaborator

The goal would be to have a deep (as possible), reflection-free, runtime-free option similar to the SimpleEquals and SimpleHashcode for toString method creation.

@ja6a
Copy link

ja6a commented Jul 4, 2017

+1

@andrei-ivanov
Copy link

I see there is a SimpleToStringPlugin, but it was disabled by the author at some point.
@highsource Can it be enabled again please? Or is it somehow broken?

@highsource
Copy link
Owner

@andrei-ivanov There's nothing to enable, it was never implemented. The class is a copy-paste of ToStringPlugin.

The problem with simple toString plugin is that it is very cumbersome to implement it in a non-strategic way. Basically I'd have to generate all the "to string" code contained in the strategies into the schema-derived classes. And "to string" strategies are ca. 3-4x larger than, say, the hash code strategy.

At the same time I don't quite understand what is the problem with an additional runtime dependency. I mean, OK, it is better without the runtime dep, but for the price of ugly code in the toString method? I really don't know.

@mattrpav
Copy link
Collaborator Author

mattrpav commented Jul 2, 2018

I was thinking the deep-as-possible is probably the wrong approach. A shallow inspection of only immediate member primitive and boxes primitives fields would cover a large number of use cases and allow for a depedency-free model jar. Scenarios that need more than first-level could then opt for the toString strategy and the runtime dependency.

Ie only “to string” member fields of these types:

String
int / Integer
short / Short
long / Long
double / double
float / Float
boolean / Boolean
etc

@highsource
Copy link
Owner

@mattrpav This would be much easier but to be honest this is very limited. Would not even cover collections or JAXBElement<T>.

But I'll think about it.

@mattrpav
Copy link
Collaborator Author

mattrpav commented Jul 2, 2018

@highsource gotcha. Perhaps, for collections a suitable solution for class:

public class MyFoo { private List<?> items... }

The toString on the collection could be:

items != null ? "items: [" + items.size() + "]" : "items: [null]"

I'm fine w/ no support for JAXBElement. I think the idea is to have an option for a bunch of easy use cases to dodge the runtime requirement, but understand that there are corner cases that cause it to jump to the full ToStringStrategy. I could see us using both. We leverege extending the ToStringStrategy to do password and other secret masking, I wouldn't expect that type of functionality in a SimpleString solution.

@laurentschoelens
Copy link
Collaborator

Follow up issue : highsource/jaxb-tools#433

@laurentschoelens laurentschoelens closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
@laurentschoelens
Copy link
Collaborator

Closing in favor of follow up issue in jaxb-tools

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

No branches or pull requests

5 participants