Comments (3)
what would happen to a nested class, ie
class Animal
class Cat
end
end
Would the root be cat
or cat_animal
? Also what json would it produce with a nested class? { "animal": { "cat": ... } }
from surrealist.
@allcentury that's a good point, thanks. I think that the least surprising way would be to have the root key as animal_cat
:
class Animal
class Cat
include Surrealist
json_schema do
{ breed: String }
end
def breed
'Bengal'
end
end
end
Animal::Cat.new.surrealize(include_root: true)
# # => '{ "animal_cat": { "breed": "Bengal" } }'
But I would love to hear opinions on this question
from surrealist.
Actually, I think that it would be better to have the last namespace as root key, e.g
Animal::Cat.new.surrealize(include_root: true)
# # => '{ "cat": { "breed": "Bengal" } }'
And add another option to include namespaces:
Animal::Cat.new.surrealize(include_namespaces: true)
# # => '{ "animal": { "cat": { "breed": "Bengal" } } }'
And maybe later add a feature to specify level of namespaces nesting, something like
BusinessSystem::Core::Domain::Cashout::Reports::Withdraws.new.surrealize(include_namespaces: true, namespace_nesting_level: 3)
# '{ "cashout": { "reports": { "withdraws": { "id": 3, "amount": 345, ... } } } }'
from surrealist.
Related Issues (20)
- Some methods are not being correctly delegated HOT 1
- Unable to override method in 1.2 HOT 3
- Question: how to create list of entities HOT 5
- Can't redefine object method with inheritance HOT 1
- How I can set a root key? HOT 2
- Inherited Surrealist::Serializer does not accept array as object HOT 5
- Nil values for Boolean type HOT 4
- Methods from included module which conflict with methods from the model don't work. HOT 1
- Pluggable type systems HOT 4
- How to qualify parameters in nested structures?
- Change API for multiple serializers HOT 6
- Build schema for collections from Surrealist::Serializer
- Default options HOT 4
- ActiveModel validations? HOT 2
- Sequel models do not work with custom serializers HOT 1
- conditional tags for json_schema HOT 3
- Inheritance doesn't work in custom serializers HOT 1
- Conflict when root and and object property share the same name HOT 1
- Serialize from hash HOT 5
- Easy access to defined schema and schema sample HOT 12
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 surrealist.