I need to convert EnrichedActivity to String as I use stream-java:3.2.4 in a Flutter application.
I get EnrichedActivity list like this:
val list : List<EnrichedActivity> = client.flatFeed("user").getEnrichedActivities(EnrichmentFlags()
.withOwnReactions()
.withRecentReactions()
.withReactionCounts()).get()
Then I try to convert the list like this:
val resultString = ObjectMapper()
.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.ALWAYS)
.writeValueAsString(list)
But some fields are erased by FasterXml-jackson (v2.9.6).
Isn't this the correct way to convert an EnrichedActivity list to String?
Note 1- Original EnrichedActivity list:
0 = {EnrichedActivity#15673}
"EnrichedActivity{id=5e02d656-27ef-11eb-88f9-128a130028af,
actor=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, verb=post,
object=Data{id=b0e249e9-8695-4161-bb24-d3980da4cdeb, data={}},
foreignID=, target=Data{id=, data={}}, time=Mon Nov 16 12:37:39
GMT+03:00 2020, origin=null, to=null, score=null,
ownReactions={like=[Reaction{id=4186ea14-f3e5-4368-8a91-eafc12e3045b,
appID=null, kind=like, userID=RqO5ns7mrYfvain3ETQpdPgIQZz1,
activityID=5e02d656-27ef-11eb-88f9-128a130028af, parent=,
ownChildren=null, latestChildren={}, childrenCounts={},
userData=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, activityData={},
extra={updated_at=2020-11-16T09:39:25.088760Z,
created_at=2020-11-16T09:39:25.088760Z}}]},
latestReactions={like=[Reaction{id=4186ea14-f3e5-4368-8a91-eafc12"
1= {EnrichedActivity#15674}
"EnrichedActivity{id=6f18988b-277d-11eb-96e2-1254437355c5,
actor=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, verb=post,
object=Data{id=11f22b84-5168-452e-b098-c9f60818d6b2, data={}},
foreignID=, target=Data{id=, data={}}, time=Sun Nov 15 23:02:05
GMT+03:00 2020, origin=null, to=null, score=null,
ownReactions={like=[Reaction{id=63471022-3e44-4d44-ad3d-6104d96a0843,
appID=null, kind=like, userID=RqO5ns7mrYfvain3ETQpdPgIQZz1,
activityID=6f18988b-277d-11eb-96e2-1254437355c5, parent=,
ownChildren=null, latestChildren={}, childrenCounts={},
userData=Data{id=RqO5ns7mrYfvain3ETQpdPgIQZz1,
data={updated_at=2020-11-11T22:46:38.568116Z,
name=RqO5ns7mrYfvain3ETQpdPgIQZz1,
created_at=2020-11-11T22:46:38.568116Z}}, activityData={},
extra={updated_at=2020-11-16T09:31:16.925141Z,
created_at=2020-11-16T09:31:16.925141Z}},
Reaction{id=9c7e0401-6ed0-47a8-b239-2669786e3340, appID=null, kind="
Note 2- The serialized form of the list above:
[ { "actor": { "id": "RqO5ns7mrYfvain3ETQpdPgIQZz1", "updated_at":
"2020-11-11T22:46:38.568116Z", "name": "RqO5ns7mrYfvain3ETQpdPgIQZz1",
"created_at": "2020-11-11T22:46:38.568116Z" }, "id":
"5e02d656-27ef-11eb-88f9-128a130028af", "object": { "id":
"b0e249e9-8695-4161-bb24-d3980da4cdeb" }, "target": { "id": "" },
"time": "2020-11-16T09:37:39.284", "verb": "post", "foreign_id": "",
"message": "test2", "latest_reactions_extra": { "like": { "next": "" }
} }, { "actor": { "id": "RqO5ns7mrYfvain3ETQpdPgIQZz1", "updated_at":
"2020-11-11T22:46:38.568116Z", "name": "RqO5ns7mrYfvain3ETQpdPgIQZz1",
"created_at": "2020-11-11T22:46:38.568116Z" }, "id":
"6f18988b-277d-11eb-96e2-1254437355c5", "object": { "id":
"11f22b84-5168-452e-b098-c9f60818d6b2" }, "target": { "id": "" },
"time": "2020-11-15T20:02:05.321", "verb": "post", "foreign_id": "",
"message": "Test", "latest_reactions_extra": { "like": { "next":
"https://stream-io-api.com/api/v1.0/reaction/activity_id/6f18988b-277d-11eb-96e2-1254437355c5/like/?id_lt=4fa212db-0125-4b4e-9a77-04e4940ec64a&limit=5&withOwnChildren=false"
} } } ]
Related
I have this situation:
This is my tree entity where each item can be a parent item or child item of one of the same entity and each of them are related to an artist.
#Entity()
#Tree("materialized-path")
export class ArtistCommissionSetupItem {
#PrimaryGeneratedColumn({type: "bigint"})
id:number
#ManyToOne(()=>Artist, artist => artist.id, {onDelete: 'CASCADE'})
#JoinColumn()
#Index()
artist:Artist
#Column()
#Index()
name:string
#Index()
#Column({nullable: true})
enabled:boolean
#TreeParent()
parent:ArtistCommissionSetupItem
#TreeChildren()
childrens:ArtistCommissionSetupItem[]
}
The thing here is that I want to get the artist with his related commission setup items and I can do that but the result of commission setup items leftJoinAndSelect method doesn't come with the items nested as tree/child tree. I want the data of commission setup items come like findTrees() method returns it.
An example of how the data come:
"commissionSetupItems": [
{
"id": "154",
"name": "Body",
"enabled": null,
"price": null,
"createdAt": "2021-09-23T21:17:05.630Z",
"updatedAt": "2021-09-23T21:17:05.630Z"
},
{
"id": "155",
"name": "icon",
"enabled": true,
"price": "120.00",
"createdAt": "2021-09-23T21:17:05.630Z",
"updatedAt": "2021-09-23T21:17:05.630Z"
},
{
"id": "156",
"name": "Headshot",
"enabled": false,
"price": "120.00",
"createdAt": "2021-09-23T21:17:05.630Z",
"updatedAt": "2021-09-23T21:17:05.630Z"
}
}
an example of how I want the data comes:
{
"commissionSetupItems": [
{
"id": 1,
"name": "Characters",
"key": "characters",
"childrens": [
{
"id": 5,
"name": "Number of characters",
"key": "number_of_characters",
"childrens": []
}
]
},
{
"id": 2,
"name": "Body",
"key": "body",
"childrens": [
{
"id": 6,
"name": "Icon",
"key": "icon",
"childrens": []
},
{
"id": 7,
"name": "Chibi",
"key": "chibi",
"childrens": []
},
{
"id": 8,
"name": "Headshot",
"key": "headshot",
"childrens": []
},
{
"id": 9,
"name": "Torso or Burst",
"key": "torso",
"childrens": []
},
{
"id": 10,
"name": "Half body",
"key": "half_body",
"childrens": []
},
{
"id": 11,
"name": "Full body",
"key": "full_body",
"childrens": []
}
]
}
}
I can't figure out how to do this.
Hello i am new in MongoDB and NodeJS. How can i sort this array of objects for example by ELO, GAMES_COUNT, TIME, users firstname etc. with MongoDB mongoose aggregate ?
Here is an examle:
"statistics": [
{"statistics": [
{
"type": "ELO",
"value": 1022
},
{
"type": "GAMES_COUNT",
"value": 5
},
{
"type": "TIME",
"value": 3112
},
],
"user": {
"_id": "1",
"firstName": "Pepa",
"lastName": "Novák",
}
},
{
"statistics": [
{
"type": "ELO",
"value": 1028
},
{
"type": "GAMES_COUNT",
"value": 4
},
{
"type": "TIME",
"value": 2151
},
],
"user": {
"_id": "2",
"firstName": "Václav",
"lastName": "Rupinsky"
}
}
]
The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject
What exactly is the best practice for matching JSON:API data collections with their respective includes. Considering the following code below....
What if I wanted to loop through each venue and display the Owners full information for each Venue Record. Does JSON:API expect me to just search the include array for the matching Owner Record
find(included,data[$i].relationships.owner.data.id);
Would find() loop through the included array to look for the owner that has the matching id as the collection items owner in the relationships object ?
$(data).each(function(item){
var owner = find(included,'owner', item.relationships.owner.data.id)
})
I have not found a resource that explains this or perhapes I am mis understanding the point of json:api. If someone can explain this or point to a resource that relates to my question. I would appreciate it.
{
"links": {
"self": "http://127.0.0.1/api/venues?include=owner"
},
"data": [
{
"id": "5c5b49188fd33c7a989ba9b6",
"type": "venues",
"attributes": {
"name": "Kreiger - Smith",
"address": "69675 Reilly Vista",
"location": {
"type": "Point",
"coordinates": [
-112.110492,
36.098948
]
},
"events": [
{
"_id": "ad52825a8f4812e92f87b8c6",
"name": "Cool Awesome Event!",
"user": "b3daa77b4c04a9551b8781d0",
"id": "ad52825a8f4812e92f87b8c6"
}
],
"created_at": "2019-02-07T14:27:13.207Z",
"updated_at": "2019-02-07T14:27:13.207Z"
},
"relationships": {
"owner": {
"data": {
"id": "b3daa77b4c04a9551b8781d0",
"type": "users"
}
}
}
},
{
"id": "5c5b49188fd33c7a989ba9b7",
"type": "venues",
"attributes": {
"name": "Oberbrunner Inc",
"address": "1132 Kenyon Stravenue",
"location": {
"type": "Point",
"coordinates": [
-112.110492,
36.098948
]
},
"events": [
{
"_id": "ad52825a8f4812e92f87b8c6",
"name": "Cool Awesome Event!",
"user": "b3daa77b4c04a9551b8781d0",
"id": "ad52825a8f4812e92f87b8c6"
}
],
"created_at": "2019-02-07T14:27:13.207Z",
"updated_at": "2019-02-07T14:27:13.207Z"
},
"relationships": {
"owner": {
"data": {
"id": "b3daa77b4c04a9551b8781d0",
"type": "users"
}
}
}
},
{
"id": "5c5b49188fd33c7a989ba9b8",
"type": "venues",
"attributes": {
"name": "Gibson - Muller",
"address": "8457 Hailie Canyon",
"location": {
"type": "Point",
"coordinates": [
-112.110492,
36.098948
]
},
"events": [
{
"_id": "ad52825a8f4812e92f87b8c6",
"name": "Cool Awesome Event!",
"user": "b3daa77b4c04a9551b8781d0",
"id": "ad52825a8f4812e92f87b8c6"
}
],
"created_at": "2019-02-07T14:27:13.208Z",
"updated_at": "2019-02-07T14:27:13.208Z"
},
"relationships": {
"owner": {
"data": {
"id": "a1881c06eec96db9901c7bbf",
"type": "users"
}
}
}
}
],
"included": [
{
"id": "b3daa77b4c04a9551b8781d0",
"type": "users",
"attributes": {
"username": "killerjohn",
"firstname": "John",
"lastname": "Chapman"
}
},
{
"id": "a1881c06eec96db9901c7bbf",
"type": "users",
"attributes": {
"username": "numerical25",
"firstname": "Billy",
"lastname": "Gordon"
}
}
]
}
This is my best possible solution. But is there a better way ? Seems like alot more coding just to find a collections associated included data
axios.get('http://127.0.0.1:3000/api/venues?include=owner').then(function(response) {
var venues = response.data.data;
var data = response.data;
for(x in venues) {
var owner = data.included.find(function(element) {
if(element.id == venues[x].relationships.owner.data.id) {
return element;
}
});
}
});
I'm getting below response from loopback when I filter with below api:
http://localhost:8001/myloopback/productDetails?q=product.productId==apple
I want to exclude the data which doesn't have property "productModel" - how can we achieve this in Loopback rest API. Is there any option to exclude property from the rest API query param? I'm new to Loopback - it would be really grateful if someone can help me to fix this
{
"myData": [{
"data": {
"product": {
"productId": "apple",
"productName": "iPhone",
"productModel": "6s"
},
"statusCode": "active",
"date": "2018-08-07T00:00:00.000Z"
},
"links": [{
"productUrl": "test"
},
{
"productImage": "test"
}
],
"info": {}
},
{
"data": {
"product": {
"productId": "apple",
"productName": "iPhone",
"productModel": "7"
},
"statusCode": "active",
"date": "2018-08-07T00:00:00.000Z"
},
"links": [{
"productUrl": "test"
},
{
"productImage": "test"
}
],
"info": {}
},
{
"data": {
"product": {
"productId": "apple",
"productName": "Macbook"
},
"statusCode": "active",
"date": "2018-08-07T00:00:00.000Z"
},
"links": [{
"productUrl": "test"
},
{
"productImage": "test"
}
],
"info": {}
}
],
"metadata": {
"count": 3,
"offset": 0
}
}
There is no such inbuilt function to do that but you can use multiple Fields filter to achieve that.