GSON Code for deserializing a nested JSON - gson

Hi my json is like this and I used gson for converting to Java, I created a top level class with all the attributes and another class that has a list. However the values are printed as null even though array size is correct. What am I doing wrong?
Gson json = new Gson();
ProductListResponse [] response = json.fromJson(str, ProductListResponse[].class);
public class ProductList {
public String code;
public String name;
public String description;
public Date lastUpdateDate;
public String lastUpdatedBy;
}
------------------------------------------------------------------------------------
public class ProductListResponse {
public ProductList plist;
}
-------------------------------------------------------------------------------------------
[
{
"product": {
"code": "RA",
"name": "Read About",
"description": "Read About"
}
},
{
"product": {
"code": "READ180",
"name": "Read180",
"description": "Read180"
}
},
{
"product": {
"code": "RLIB",
"name": "Read180 Library Catalog",
"description": "Read180 Library Catalog",
"last_udapte_date": "2010-12-07 00:00:00.0",
"last_updated_by": "fdixon00"
}
},
{
"product": {
"code": "EREADS",
"name": "Read180 eReads",
"description": "Read180 eReads"
}
},
{
"product": {
"code": "RSKILL",
"name": "Read180 rSkills",
"description": "Read180 rSkills",
"last_udapte_date": "2010-09-20 00:00:00.0",
"last_updated_by": "fdixon00"
}
},
{
"product": {
"code": "POOL",
"name": "Reference Asset Pool",
"description": "Reference Asset Pool"
}
},
{
"product": {
"code": "SU",
"name": "Scholastic U",
"description": "Scholastic U"
}
},
{
"product": {
"code": "TR8TS",
"name": "Six Traits of Writing",
"description": "Six Traits of Writing"
}
},
{
"product": {
"code": "TFX",
"name": "TrueFlix",
"description": "TrueFlix",
"last_udapte_date": "2012-08-20 10:47:46.0",
"last_updated_by": "wbyler00"
}
}
]

It's just a naming chaos: In ProductListResponse rename plist to product and it'll work at once.

Related

How in strapi graphql I can pull records from a given month

Hi I would like to draw from graphql only those records whose date is equal to the month - August
If I want to pull another month, it is enough to replace it only in the query. At the moment, my query takes all the months instead of the ones it gives inside the filter
schema.json
{
"kind": "collectionType",
"collectionName": "product_popularities",
"info": {
"singularName": "product-popularity",
"pluralName": "product-popularities",
"displayName": "Popularity",
"description": ""
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"podcast": {
"type": "relation",
"relation": "manyToOne",
"target": "api::product.products",
"inversedBy": "products"
},
"value": {
"type": "integer"
},
"date": {
"type": "date"
}
}
}
My query
query {
Popularities(filters: {date: {contains: [2022-08]}}) {
data {
attributes {
date
value
}
}
}
}
Response
{
"data": {
"Popularities": {
"data": [
{
"attributes": {
"date": "2022-08-03",
"value": 50
}
},
{
"attributes": {
"date": "2022-08-04",
"value": 1
}
},
{
"attributes": {
"date": "2022-08-10",
"value": 100
}
},
{
"attributes": {
"date": "2022-07-06",
"value": 20
}
}
]
}
}
}

Extract value of array and add in the same select mongoDB

I am new to the mongoDB aggregation and I have this situation. I have this Json and I need to convert by "select" this object:
{
"type": "PF",
"code": 12345
"Name": Darth Vader,
"currency": "BRL",
"status": "SINGLE",
"adress": [
{
"localization": "DEATH STAR",
"createDate": 1627990848665
},
{
"localization": "TATOOINE",
"createDate": 1627990555665
},
]
}
this way:
{
"type": "PF",
"code": 12345
"Name": Darth Vader,
"currency": "BRL",
"status": "SINGLE",
"localization": "DEATH STAR",
"createDate": 1627990848665
},
{
"type": "PF",
"code": 12345
"Name": Darth Vader,
"currency": "BRL",
"status": "SINGLE",
"localization": "TATOOINE",
"createDate": 1627990555665
}
So, after my query is complete, I will have 02 objects instead of 01. How can I do this?
I would like to do this via select because after converting I will sort by createDate and limit the number of records to return to the API. I'm using Criteria em my project.
The way to do this is $unwind, this will make 1 copy of the document, for each member of the array.
Test code here
db.collection.aggregate([
{
"$unwind": {
"path": "$user.adress"
}
},
{
"$set": {
"user": {
"$mergeObjects": [
"$user",
"$user.adress"
]
}
}
},
{
"$unset": [
"user.adress"
]
},
{
"$sort": {
"createDate": 1
}
},
{
"$limit": 10
}
])
Edit1 (the above is if user is a field, if it was the name of the collection)
$$ROOT is a system variable that has as value all the document
Test code here
Query
db.collection.aggregate([
{
"$unwind": {
"path": "$adress"
}
},
{
"$replaceRoot": {
"newRoot": {
"$mergeObjects": [
"$$ROOT",
"$adress"
]
}
}
},
{
"$unset": [
"adress"
]
},
{
"$sort": {
"createDate": 1
}
},
{
"$limit": 10
}
])

In json schema, how to define an enum with description of each elements in the enum?

In json schema, I can simply define a code list using "enum" with a list of code that is available, for example:
{
"type": "object",
"properties": {
"group": {
"type":"string",
"$ref": "#/definitions/Group"
}
},
"definitions": {
"Group": {
"enum": ["A","B"]
}
}
}
And the following payload would be valid:
{
"group": "B"
}
However, I try to provide the description in the schema to the user where "A" = "Group A", "B" = "Group B". Something like:
{
"type": "object",
"properties": {
"group": {
"type":"string",
"$ref": "#/definitions/Group"
}
},
"definitions": {
"Group": {
"enum": [
{"code":"A",
"description": "Group A"
},
{"code":"B",
"description": "Group B"
}
]
}
}
}
But I don't want to change the structure of the payload (no "description" field needed)
The description is more for documentation purposes that users can refer to.
Is there a good practice that can be used here?
Thank you
You can use anyOf with const instead of enum. Then you can use title or description for documentation.
{
"anyOf": [
{
"const": "A",
"title": "Group A"
},
{
"const": "B",
"title": "Group B"
}
]
}
It depends on your tool-chain. For example the jsonschema2md allows to use meta:enum attribute for descriptions:
{
"type": "object",
"properties": {
"group": {
"type":"string",
"$ref": "#/definitions/Group"
}
},
"definitions": {
"Group": {
"enum": ["A", "B"],
"meta:enum": {
"A": "Group A",
"B": "Group B"
}
}
}
}

Data view mapping in Power BI visuals

Good day
I am creating custom visualization on d3js and pbiviz for powerbi
Here is the code in capabilities.js:
{
"dataRoles":[
{
"displayName": "HoleDepth",
"name": "depth",
"kind": "Grouping"
},
{
"displayName": "Days",
"name": "days",
"kind": "Measure"
},
{
"displayName": "Diametrs",
"name": "diametrs",
"kind": "Measure"
},
{
"displayName": "Sensor1",
"name": "sensor_1",
"kind": "Measure"
},
{
"displayName": "Sensor2",
"name": "sensor_2",
"kind": "Measure"
},
{
"displayName": "Sensor3",
"name": "sensor_3",
"kind": "Measure"
},
{
"displayName": "Sensor4",
"name": "sensor_4",
"kind": "Measure"
}
],
"dataViewMappings": [
{
"categorical": {
"categories": {
"for": { "in": "depth" }
},
"values": {
"select":[
{ "bind": { "to": "days" } },
{ "bind": { "to": "diametrs" } },
{ "bind": { "to": "sensor_1" } },
{ "bind": { "to": "sensor_2" } },
{ "bind": { "to": "sensor_3" } },
{ "bind": { "to": "sensor_4" } }
]
}
}
}
]
}
But in visualization it is inconvenient to use categorical -> values array
Is it possible to categorical -> values
was like an object with keys?
I do not think that this is possible directly through data mapping. What I usually do if I want to have data prepared in the specific format, convenient for visualization with d3.js, is the custom function that transforms the data from VisualUpdateOptions.
Then I call this function inside public update(options: VisualUpdateOptions)

Array map equivalent for GraphQL query

I was wondering if it is possible to reduce the return payload of this query Result:
{
"nodes": [
{
"topic": {
"name": "typescript"
}
},
{
"topic": {
"name": "discord"
}
},
{
"topic": {
"name": "discord-bot"
}
},
{
"topic": {
"name": "discordjs"
}
},
{
"topic": {
"name": "discordjs-commando"
}
},
{
"topic": {
"name": "mbti-personality"
}
},
{
"topic": {
"name": "mbti"
}
},
{
"topic": {
"name": "typeorm"
}
}
]
}
Into something like this:
{
"nodes": ["typescript", "discord", "discord-bot", "discordjs", "discordjs-commando", "mbti-personality", "mbti", "typeorm"]
}
I find it very verbose and unnecessary
I am not the owner of the API. So that concerns only the query. (It the Github's GraphQL API)
I'm new to GraphQL and don't undestand the principles yet, so I don't know the terms to search for.

Resources