Comments (12)
Ah, got it.
Yes, it would be bad to edit a generated file. For that reason I think it is worth writing a properly gofmt
'ed file. It will play nicely for those that do gofmt
checks in their build process.
from easyjson.
The issue is that bootstrapping code needs to import the package to do reflection on required structs and this doesn't quite work with main package.
I'll look into the options to make this case work.
As for gofmt, does this cause any trouble? The only case I can think of is when you edit it and gofmt will be run automatically, but it's generally a bad practice to manually edit an autogenerated file.
from easyjson.
@kmansoft Probably didn't explain myself well, sorry. I've only used this library and don't know about its internals, but wanted to suggest this limitation (at least until it's implemented) to be notes in the readme.
from easyjson.
And it will play nicely for those who use pre-commit git hooks with gofmt too.
from easyjson.
That's perfectly reasonable. I just wanted a use-case to be sure what scenario I am fixing. I've added 'gofmt -w' invocation, see #3.
Haven't gotten to fixing the main package yet, though.
from easyjson.
you could avoid the whole issue likely by using the AST packages instead of creating a executable and using reflection. would also make it possible to regenerate the json methods when you remove a field from a structure without having to delete the easyjson file.
from easyjson.
@james-lawrence Using AST would also be quite fast to generate. That's exactly what I tried doing at first. Unfortunately the code turned out to be more complex than I was willing to support. Maybe I was just using it the wrong way.
On the issue: it seems to be a rather rare scenario, so I didn't get to it yet. I'll have some time to experiment with it over this weekend, looks like it won't be too hard to fix.
from easyjson.
I'm having this problem too, on a small enough package that I don't want to split the pair of structs I need to play with to another package. Any news ?
from easyjson.
Any news on the AST parser approach?
The use case is as mentioned above by @elwinar - sometimes it's convenient to keep your structs in same source tree and not split into a separate package just because of EasyJSON.
from easyjson.
This should probably be noted in the Readme (for now?). It is a limitation of the library and will confuse people who try to use the library after reading through it.
from easyjson.
@TheSilvus I'm just saying that it would be nice to be able to parse local files (as opposed to having to reference external compile-able packages), which means taking the AST approach to generating metadata. I know this was in the plans at some point, but no actual progress.
Are you saying that the plans have changed, and this definitely won't be implemented?
from easyjson.
Fix of this was offered in #236
from easyjson.
Related Issues (20)
- MarshalToWriter does not pool buffers since Go 1.17
- Detailed unmarshalling error information
- go1.18
- Struct with embedding struct pointer set to nill causes panic HOT 1
- go 1.18 generics support HOT 3
- easyjson didn't generate all data. MFTI/perfomance/json example HOT 1
- Tag a new version
- Undocumented 'required' struct tag
- String JSON field to int struct field
- Interface types generate associated functions. Maybe they shouldn't.
- (v *RawMessage) UnmarshalJSON(data []byte) does not make copy of data
- Cannot handle uint64 just like std json
- cant gen code in main package HOT 1
- Impact of sanctions on this library
- json.Valid breaks in SkipRecursive
- errors!
- Cli tool type missmatch
- []byte field is incorrectly generated as a string field, making it unmarshalable
- golang 1.21 and 1.22
- why not use map/hash instead of for-loop HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from easyjson.