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

Make helper methods of WriterBasedJsonGenerator non-final to allow overriding #1305

Merged
merged 5 commits into from
Jun 13, 2024

Conversation

zhangOranges
Copy link
Contributor

The protected method removes the final to allow users to rewrite the method and implement their own logic

The protected method removes the final to allow users to rewrite the method and implement their own logic
@cowtowncoder
Copy link
Member

I am ok with targeted removal of final (with all the caveats that sub-classing of this type is strongly discouraged as these methods are not part of API in the sense that no backwards-compatibility is implied across minor versions) for methods. But static fields should remain final, they are not meant to be changed.

@cowtowncoder
Copy link
Member

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com.
This is needed once before the first contribution; after that good for all future PRs.

@zhangOranges
Copy link
Contributor Author

Okay, I want to add some of my own logical operations before writing to outBuffer, but I couldn't find the provided entry, so I saw the WriterBasedJsonGenerator class. However, some of the protected methods were declared final, which confused me. Is there any other better way for me to operate, similar to an AOP

@cowtowncoder
Copy link
Member

@zhangOranges One thing that might work JsonGeneratorDelegate:

src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java

which could intercept calls. It depends on kinds of changes you need to make.
You basically use it to "wrap" a real generator, and by default it just delegates all calls; but you can override whatever public methods you want. Since it operates on public API it is more limited, but also much safer and easier to maintain approach.

@zhangOranges
Copy link
Contributor Author

JsonGeneratorDelegate

{
//test
"demo":"1"
} Annotation test is what I want to add, JsonGeneratorDelegate may not meet my needs, right?

@zhangOranges
Copy link
Contributor Author

@zhangOranges One thing that might work JsonGeneratorDelegate:

src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java

which could intercept calls. It depends on kinds of changes you need to make. You basically use it to "wrap" a real generator, and by default it just delegates all calls; but you can override whatever public methods you want. Since it operates on public API it is more limited, but also much safer and easier to maintain approach.

I want to add some other things before writing the correct JSON key value

@zhangOranges
Copy link
Contributor Author

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:

https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf

The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

@cowtowncoder
Copy link
Member

@zhangOranges One thing that might work JsonGeneratorDelegate:

src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java

which could intercept calls. It depends on kinds of changes you need to make. You basically use it to "wrap" a real generator, and by default it just delegates all calls; but you can override whatever public methods you want. Since it operates on public API it is more limited, but also much safer and easier to maintain approach.

I want to add some other things before writing the correct JSON key value

It would be possible to override writeFieldName(), call writeRaw() on delegate before forwarding writeFieldName().

@cowtowncoder
Copy link
Member

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:
https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

What some contributors have done is to use an app that takes PDF, allows adding text to fill in the fields (add text in approximate location). That works for me.

@zhangOranges
Copy link
Contributor Author

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:
https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

What some contributors have done is to use an app that takes PDF, allows adding text to fill in the fields (add text in approximate location). That works for me.

Which email to send after signing

@zhangOranges
Copy link
Contributor Author

@zhangOranges One thing that might work JsonGeneratorDelegate:

src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java

which could intercept calls. It depends on kinds of changes you need to make. You basically use it to "wrap" a real generator, and by default it just delegates all calls; but you can override whatever public methods you want. Since it operates on public API it is more limited, but also much safer and easier to maintain approach.

I want to add some other things before writing the correct JSON key value

It would be possible to override writeFieldName(), call writeRaw() on delegate before forwarding writeFieldName().

WriteFieldName will add a comma to the end of the previous execution, so this method is not feasible

@cowtowncoder
Copy link
Member

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:
https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

What some contributors have done is to use an app that takes PDF, allows adding text to fill in the fields (add text in approximate location). That works for me.

Which email to send after signing

I mentioned this earlier; "cla@fasterxml.com"

@zhangOranges
Copy link
Contributor Author

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:
https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

What some contributors have done is to use an app that takes PDF, allows adding text to fill in the fields (add text in approximate location). That works for me.

Which email to send after signing

I mentioned this earlier; "cla@fasterxml.com"

ok

@zhangOranges
Copy link
Contributor Author

Aside from requested change wrt static fields, one thing I'd need before merging is CLA (unless already received one), from:
https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com. This is needed once before the first contribution; after that good for all future PRs.

Is there any other simple signature method? I currently don't have a printer

What some contributors have done is to use an app that takes PDF, allows adding text to fill in the fields (add text in approximate location). That works for me.

Which email to send after signing

I mentioned this earlier; "cla@fasterxml.com"

has been sent

@cowtowncoder
Copy link
Member

Ok received the first CLA and while it's almost good asked for minor edit (so there's name and github id both).

@zhangOranges
Copy link
Contributor Author

Ok received the first CLA and while it's almost good asked for minor edit (so there's name and github id both).

has been sent

@cowtowncoder
Copy link
Member

CLA received.

@cowtowncoder cowtowncoder changed the title Update WriterBasedJsonGenerator.java Make helper methods of WriterBasedJsonGenerator non-final to allow overriding Jun 13, 2024
@cowtowncoder cowtowncoder added the 2.18 Issues planned at earliest for 2.18 label Jun 13, 2024
@cowtowncoder cowtowncoder added this to the 2.18.0 milestone Jun 13, 2024
@cowtowncoder cowtowncoder merged commit 4a13a2f into FasterXML:2.18 Jun 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Issues planned at earliest for 2.18
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants