halbuilder / halbuilder-json Goto Github PK
View Code? Open in Web Editor NEWHalBuilder JSON Support
HalBuilder JSON Support
Hi,
Currently, null values in objects are not allowed, as JsonRepresentationReader uses Guava's ImmutableMap internally, which does not permit null keys or values. While it may be dubious practice to have a null value (as returning a null value from a Java Map may mean either the key does not exist or it does exist and is null), however, this is still valid JSON, which means it probably should be handled.
The simplest solution looks to be to remove the ImmutableMap.copyOf wrapper.
example failing HAL extract:
{
....
"page": {
"offset": null,
"limit": null
},
...
}
Thanks.
Hi,
See below, I would expect the _embedded.items.applicants not to be an array.
{
"_links": {
"self": {
"href": "https://localhost:8443/applications"
}
},
"_embedded": {
"items": [
{
"_links": {
"self": {
"href": "https://localhost:8443/applications/11111111"
},
"applicants": [
{
"href": "https://localhost:8443/applications/11111111/applicants"
}
]
}
}
]
}
}
Is there plan to support Joda Date time ? Currently, I am converting my date into W3C formatted string, but it will be great if we can add support for Joda Date Time. Let me know , and I can submit a PR for the same.
As far as I've checked it's not possible to add a sub representation which will yield an empty array in the "_embedded" field.
I've modified the repositories to enable this.
Trying to serialise this representation:
String href = "customer/123456";
ReadableRepresentation party = newBaseResource(href)
.withLink("ns:users", BASE_URL + href + "?users")
.withRepresentation("ns:users", representationFactory
.newRepresentation("1")
.setEmptySubRepresentation(true));
will yield the following JSON:
{
"_links" : {
"curies" : [ {
"href" : "https://example.com/apidocs/ns/{rel}",
"name" : "ns",
"templated" : true
}, {
"href" : "https://example.com/apidocs/role/{rel}",
"name" : "role",
"templated" : true
} ],
"self" : {
"href" : "https://example.com/api/customer/123456"
},
"ns:parent" : {
"href" : "https://example.com/api/customer/1234",
"name" : "bob",
"title" : "The Parent",
"hreflang" : "en"
},
"ns:users" : {
"href" : "https://example.com/api/customer/123456?users"
}
},
"_embedded" : {
"ns:users" : [ ]
}
}
Hi,
If folks is an array of strings, this:
rep.withProperty("folks", user.getFolks());
produces this:
"folks":["Bob","Carol","Ted"],
So arrays are output successfully.
Unfortunately when reading it back in this line in readProperties:
resource.withProperty(fieldName, field.isNull() ? null : field.asText());
produces an empty string.
I can't see anything in the HAL specification that says properties can't be arrays (in fact it claims everything except the links can be any valid JSON).
Is this an intentional behaviour or a bug?
Thanks
If you call representationReader.read(reader);
with an HAL compliant JSON structure you can't access the link objects via representation.getLinkByRel("books")
.
Internaly the read function calls readLinks
function in JsonRepresentationReader. At the second line the function tries to get an Iterator with all fields of the links. (rootNode.get(LINKS).fields()
). This nerver works because the method fields() method of the ArrayNode class isn't overridden (FasterXML jackson-databind Issue).
I have a JSON with the following property:
...
"id" : 63,
"primary_number" : {
"ac" : "221",
"cc" : "49",
"sn" : "16804109"
},
"password" : "secret",
....
The JsonRepresentationReader class uses readProperties() to read these property but it only tests if the value is a JSON Arrays, in which case it creates an List, and else stores it as String.
In my example the correct behaviour for the "primary_number" property would be to check for a JSON Object and store that as HashMap.
Currenlty JSON Fields of type Number are silently converted to Java Strings. A more natural choice would be BigDecimal.
Hi Mark, do you mind pushing the latest code to maven? I'm having an issue with NPEs deserializing maps that have null
values. I think this commit will probably resolve the issue since the root of the problem is in ImmutableMap
.
Thanks!
Damon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.