Comments (10)
Can you provide sample code?
from easyjson.
type MyInterface interface {
Hello() string
}
type MyString string
func (ms MyString) Hello() string {
return string(ms)
}
type TestObject struct {
Field MyInterface
}
func main() {
obj := TestObject{}
obj.Field = MyString("AAA")
b, _ := json.Marshal(&obj)
fmt.Println("OP->", string(b))
}
easyjson code generation fails here with error
interface type MyInterface not supported: only interface{} is allowed.
Can you please let me know whether easyjson will fix this api/service break with std json?
from easyjson.
It is impossible to do it without reflection, so I think the only way is to generate code that will run default (reflection-based) marshaller for this field.
from easyjson.
I think it possible to have just a little bit of reflection overhead in stdlib marshaler if MyString will have generaded marshallers with easyjson ( implements json.Marshaler interface )
from easyjson.
My preference would be if easyjson doesn't support something (such as a non-empty interface) fallback on the standard json.Marshal. There could be a switch to enable this behavior and the default can be off (for backwards compatibility sake).
from easyjson.
@GoWebProd Why was this closed? I think @deusnefum's suggestion is not unreasonable.
from easyjson.
It should also be noted that the error generated by easyjson give absolutely no context as to where the error occurred in the source file.
from easyjson.
@dgoodine Hello, issue closed because easyjson not supports non-empty interfaces due to the lack of the ability to use reflect lib. If you want to use interface in struct, please set type to interface{}
(empty interface)
from easyjson.
Why can't easyjson use the reflect lib? At least just for those fields whose type is an interface.
from easyjson.
The task of easyjson is parsing and serialization quickly. Reflect does not allow this.
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.