FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.25k stars 773 forks source link

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

Closed zhangOranges closed 3 months ago

zhangOranges commented 3 months ago

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

cowtowncoder commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

JsonGeneratorDelegate

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

zhangOranges commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

@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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

zhangOranges commented 3 months ago

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 commented 3 months ago

CLA received.