I have the following code in my JAX.RS ExceptionMapper:
#Override
public Response toResponse(ResponseStatusCodeException ex) {
ResponseStatusCode newEx = new ResponseStatusCode(ex);
return Response.status(ex.getStatus()).entity(newEx).type(MediaType.APPLICATION_JSON).build();
}
This generates a JSON response that includes a full exception stack trace starting in the Response.status() line.
How can I make the ExceptionMapper just to return the JSON encoded properties for the newEx class. I have even tried making ResponseStatusCode a POJO not extending Exception but the stack trace is always included in the response.
I am using Websphere Liberty profile 8.5.5.8.
Thanks
Edited: Let me add the JSON generated:
{
"message": "Language en is not currently available",
"status": 500,
"username": "901353fa-b43e-4e86-b12f-6d502a9e8a78",
"localizedMessage": "Language en is not currently available",
"stackTrace": [
{
"fileName": "ResponseStatusCodeExceptionHandler.java",
"lineNumber": 14,
"className": "com.servengine.ws.rs.ResponseStatusCodeExceptionHandler",
"methodName": "toResponse",
"nativeMethod": false
},
{
"fileName": "ResponseStatusCodeExceptionHandler.java",
"lineNumber": 1,
"className": "com.servengine.ws.rs.ResponseStatusCodeExceptionHandler",
"methodName": "toResponse",
"nativeMethod": false
},
{
"fileName": "ExceptionUtils.java",
"lineNumber": 90,
"className": "org.apache.cxf.jaxrs.utils.ExceptionUtils",
"methodName": "convertFaultToResponse",
"nativeMethod": false
},
{
"fileName": "JAXRSUtils.java",
"lineNumber": 1621,
"className": "org.apache.cxf.jaxrs.utils.JAXRSUtils",
"methodName": "convertFaultToResponse",
"nativeMethod": false
},
{
"fileName": "JAXRSInvoker.java",
"lineNumber": 324,
"className": "org.apache.cxf.jaxrs.JAXRSInvoker",
"methodName": "handleFault",
"nativeMethod": false
},
{
"fileName": "JAXRSInvoker.java",
"lineNumber": 213,
"className": "org.apache.cxf.jaxrs.JAXRSInvoker",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "LibertyJaxRsInvoker.java",
"lineNumber": 366,
"className": "com.ibm.ws.jaxrs20.server.LibertyJaxRsInvoker",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "JAXRSInvoker.java",
"lineNumber": 99,
"className": "org.apache.cxf.jaxrs.JAXRSInvoker",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "ServiceInvokerInterceptor.java",
"lineNumber": 59,
"className": "org.apache.cxf.interceptor.ServiceInvokerInterceptor$1",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "ServiceInvokerInterceptor.java",
"lineNumber": 96,
"className": "org.apache.cxf.interceptor.ServiceInvokerInterceptor",
"methodName": "handleMessage",
"nativeMethod": false
},
{
"fileName": "PhaseInterceptorChain.java",
"lineNumber": 307,
"className": "org.apache.cxf.phase.PhaseInterceptorChain",
"methodName": "doIntercept",
"nativeMethod": false
},
{
"fileName": "ChainInitiationObserver.java",
"lineNumber": 124,
"className": "org.apache.cxf.transport.ChainInitiationObserver",
"methodName": "onMessage",
"nativeMethod": false
},
{
"fileName": "AbstractHTTPDestination.java",
"lineNumber": 256,
"className": "org.apache.cxf.transport.http.AbstractHTTPDestination",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "AbstractJaxRsWebEndpoint.java",
"lineNumber": 134,
"className": "com.ibm.ws.jaxrs20.endpoint.AbstractJaxRsWebEndpoint",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "IBMRestServlet.java",
"lineNumber": 149,
"className": "com.ibm.websphere.jaxrs.server.IBMRestServlet",
"methodName": "handleRequest",
"nativeMethod": false
},
{
"fileName": "IBMRestServlet.java",
"lineNumber": 107,
"className": "com.ibm.websphere.jaxrs.server.IBMRestServlet",
"methodName": "doPost",
"nativeMethod": false
},
{
"fileName": "HttpServlet.java",
"lineNumber": 707,
"className": "javax.servlet.http.HttpServlet",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "IBMRestServlet.java",
"lineNumber": 99,
"className": "com.ibm.websphere.jaxrs.server.IBMRestServlet",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "ServletWrapper.java",
"lineNumber": 1287,
"className": "com.ibm.ws.webcontainer.servlet.ServletWrapper",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "ServletWrapper.java",
"lineNumber": 778,
"className": "com.ibm.ws.webcontainer.servlet.ServletWrapper",
"methodName": "handleRequest",
"nativeMethod": false
},
{
"fileName": "ServletWrapper.java",
"lineNumber": 475,
"className": "com.ibm.ws.webcontainer.servlet.ServletWrapper",
"methodName": "handleRequest",
"nativeMethod": false
},
{
"fileName": "WebAppFilterChain.java",
"lineNumber": 146,
"className": "com.ibm.ws.webcontainer.filter.WebAppFilterChain",
"methodName": "invokeTarget",
"nativeMethod": false
},
{
"fileName": "WebAppFilterChain.java",
"lineNumber": 78,
"className": "com.ibm.ws.webcontainer.filter.WebAppFilterChain",
"methodName": "doFilter",
"nativeMethod": false
},
{
"fileName": "WebAppFilterManager.java",
"lineNumber": 1020,
"className": "com.ibm.ws.webcontainer.filter.WebAppFilterManager",
"methodName": "doFilter",
"nativeMethod": false
},
{
"fileName": "WebAppFilterManager.java",
"lineNumber": 1142,
"className": "com.ibm.ws.webcontainer.filter.WebAppFilterManager",
"methodName": "invokeFilters",
"nativeMethod": false
},
{
"fileName": "CacheServletWrapper.java",
"lineNumber": 81,
"className": "com.ibm.ws.webcontainer.servlet.CacheServletWrapper",
"methodName": "__handleRequest",
"nativeMethod": false
},
{
"fileName": "CacheServletWrapper.java",
"lineNumber": -1,
"className": "com.ibm.ws.webcontainer.servlet.CacheServletWrapper",
"methodName": "handleRequest",
"nativeMethod": false
},
{
"fileName": "WebContainer.java",
"lineNumber": 928,
"className": "com.ibm.ws.webcontainer.WebContainer",
"methodName": "handleRequest",
"nativeMethod": false
},
{
"fileName": "DynamicVirtualHost.java",
"lineNumber": 262,
"className": "com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "HttpDispatcherLink.java",
"lineNumber": 955,
"className": "com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "HttpDispatcherLink.java",
"lineNumber": 341,
"className": "com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink",
"methodName": "ready",
"nativeMethod": false
},
{
"fileName": "HttpInboundLink.java",
"lineNumber": 470,
"className": "com.ibm.ws.http.channel.internal.inbound.HttpInboundLink",
"methodName": "handleDiscrimination",
"nativeMethod": false
},
{
"fileName": "HttpInboundLink.java",
"lineNumber": 404,
"className": "com.ibm.ws.http.channel.internal.inbound.HttpInboundLink",
"methodName": "handleNewRequest",
"nativeMethod": false
},
{
"fileName": "HttpInboundLink.java",
"lineNumber": 284,
"className": "com.ibm.ws.http.channel.internal.inbound.HttpInboundLink",
"methodName": "processRequest",
"nativeMethod": false
},
{
"fileName": "HttpInboundLink.java",
"lineNumber": 255,
"className": "com.ibm.ws.http.channel.internal.inbound.HttpInboundLink",
"methodName": "ready",
"nativeMethod": false
},
{
"fileName": "NewConnectionInitialReadCallback.java",
"lineNumber": 174,
"className": "com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback",
"methodName": "sendToDiscriminators",
"nativeMethod": false
},
{
"fileName": "NewConnectionInitialReadCallback.java",
"lineNumber": 83,
"className": "com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback",
"methodName": "complete",
"nativeMethod": false
},
{
"fileName": "WorkQueueManager.java",
"lineNumber": 504,
"className": "com.ibm.ws.tcpchannel.internal.WorkQueueManager",
"methodName": "requestComplete",
"nativeMethod": false
},
{
"fileName": "WorkQueueManager.java",
"lineNumber": 574,
"className": "com.ibm.ws.tcpchannel.internal.WorkQueueManager",
"methodName": "attemptIO",
"nativeMethod": false
},
{
"fileName": "WorkQueueManager.java",
"lineNumber": 929,
"className": "com.ibm.ws.tcpchannel.internal.WorkQueueManager",
"methodName": "workerRun",
"nativeMethod": false
},
{
"fileName": "WorkQueueManager.java",
"lineNumber": 1018,
"className": "com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 1142,
"className": "java.util.concurrent.ThreadPoolExecutor",
"methodName": "runWorker",
"nativeMethod": false
},
{
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 617,
"className": "java.util.concurrent.ThreadPoolExecutor$Worker",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "Thread.java",
"lineNumber": 745,
"className": "java.lang.Thread",
"methodName": "run",
"nativeMethod": false
}
],
"suppressed": [
]
}
And the POJO:
package com.servengine.ws.rs;
public class ResponseStatusCode extends Exception {
private static final long serialVersionUID = 1L;
private int status;
private String message, username, code;
public ResponseStatusCode(ResponseStatusCodeException exception) {
this.message = exception.getMessage();
this.username = exception.getUsername();
this.code = exception.getCode();
this.status = exception.getStatus();
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
If the class to be marshalled to JSON extends Exception, a stack trace will be included. I changed it to Serializable, which I had not done yet, and no stack trace is included.
Many thanks to #peeskillet for his replies.
If you are using jackson to marshal POJO to JSON, you may try this:
#JsonIgnoreProperties(value = "stackTrace")
public class ResponseStatusCode extends Exception
Related
I have this API call wherein I ask Nutritionix(API provider) for food data given a search of food name. I've already finished my JSON deserialization, however I had to serialize some parts of the response(not all) so I can put it in my database, but when I try to deserialize the Firebase data so my user can use it in my application. (Use Case is when a user force-quits the application, all locally stored variables will get cleared, thus upon launch of application I check if there is already a record in the db that the user has already logged food for breakfast/lunch/dinner today, thus just showing the saved food log in the db)
Here is what the response looks like:
{
"foods": [
{
"food_name": "cheeseburger",
"brand_name": null,
"serving_qty": 1,
"serving_unit": "item",
"serving_weight_grams": 199,
"nf_calories": 535.31,
"nf_total_fat": 28.66,
"nf_saturated_fat": 14,
"nf_cholesterol": 95.52,
"nf_sodium": 1176.09,
"nf_total_carbohydrate": 39.24,
"nf_dietary_fiber": 2.39,
"nf_sugars": 7.16,
"nf_protein": 30.27,
"nf_potassium": 443.77,
"nf_p": 364.17,
"full_nutrients": [
{
"attr_id": 203,
"value": 30.2679
},
{
"attr_id": 204,
"value": 28.656
},
{
"attr_id": 205,
"value": 39.2428
},
{
"attr_id": 207,
"value": 4.5969
},
{
"attr_id": 208,
"value": 535.31
},
{
"attr_id": 209,
"value": 25.87
},
{
"attr_id": 210,
"value": 0.2985
},
{
"attr_id": 211,
"value": 1.8507
},
{
"attr_id": 212,
"value": 2.5671
},
{
"attr_id": 213,
"value": 0.9353
},
{
"attr_id": 214,
"value": 1.5124
},
{
"attr_id": 221,
"value": 0
},
{
"attr_id": 255,
"value": 96.2364
},
{
"attr_id": 262,
"value": 0
},
{
"attr_id": 263,
"value": 0
},
{
"attr_id": 268,
"value": 2242.73
},
{
"attr_id": 269,
"value": 7.164
},
{
"attr_id": 291,
"value": 2.388
},
{
"attr_id": 301,
"value": 356.21
},
{
"attr_id": 303,
"value": 2.0298
},
{
"attr_id": 304,
"value": 51.74
},
{
"attr_id": 305,
"value": 364.17
},
{
"attr_id": 306,
"value": 443.77
},
{
"attr_id": 307,
"value": 1176.09
},
{
"attr_id": 309,
"value": 5.6317
},
{
"attr_id": 312,
"value": 0.1493
},
{
"attr_id": 315,
"value": 0.3244
},
{
"attr_id": 317,
"value": 49.153
},
{
"attr_id": 318,
"value": 471.63
},
{
"attr_id": 319,
"value": 93.53
},
{
"attr_id": 320,
"value": 101.49
},
{
"attr_id": 321,
"value": 93.53
},
{
"attr_id": 322,
"value": 1.99
},
{
"attr_id": 323,
"value": 0.398
},
{
"attr_id": 324,
"value": 5.97
},
{
"attr_id": 328,
"value": 0.199
},
{
"attr_id": 334,
"value": 3.98
},
{
"attr_id": 337,
"value": 1611.9
},
{
"attr_id": 338,
"value": 33.83
},
{
"attr_id": 341,
"value": 5.4924
},
{
"attr_id": 342,
"value": 0.6368
},
{
"attr_id": 343,
"value": 0.1194
},
{
"attr_id": 345,
"value": 0
},
{
"attr_id": 346,
"value": 0
},
{
"attr_id": 347,
"value": 0
},
{
"attr_id": 401,
"value": 0.597
},
{
"attr_id": 404,
"value": 0.2368
},
{
"attr_id": 405,
"value": 0.5174
},
{
"attr_id": 406,
"value": 8.0595
},
{
"attr_id": 410,
"value": 1.1741
},
{
"attr_id": 415,
"value": 0.1851
},
{
"attr_id": 417,
"value": 31.84
},
{
"attr_id": 418,
"value": 3.4825
},
{
"attr_id": 421,
"value": 75.023
},
{
"attr_id": 429,
"value": 0
},
{
"attr_id": 430,
"value": 8.756
},
{
"attr_id": 431,
"value": 23.88
},
{
"attr_id": 432,
"value": 7.96
},
{
"attr_id": 435,
"value": 47.76
},
{
"attr_id": 601,
"value": 95.52
},
{
"attr_id": 606,
"value": 13.9957
},
{
"attr_id": 607,
"value": 0.3861
},
{
"attr_id": 608,
"value": 0.1313
},
{
"attr_id": 609,
"value": 0.0975
},
{
"attr_id": 610,
"value": 0.2149
},
{
"attr_id": 611,
"value": 0.2527
},
{
"attr_id": 612,
"value": 1.4428
},
{
"attr_id": 613,
"value": 7.2177
},
{
"attr_id": 614,
"value": 3.7651
},
{
"attr_id": 615,
"value": 0.0398
},
{
"attr_id": 617,
"value": 10.6306
},
{
"attr_id": 618,
"value": 2.0079
},
{
"attr_id": 619,
"value": 0.2527
},
{
"attr_id": 620,
"value": 0.0577
},
{
"attr_id": 621,
"value": 0
},
{
"attr_id": 624,
"value": 0
},
{
"attr_id": 625,
"value": 0.2149
},
{
"attr_id": 626,
"value": 0.9174
},
{
"attr_id": 627,
"value": 0.1552
},
{
"attr_id": 628,
"value": 0.0975
},
{
"attr_id": 629,
"value": 0
},
{
"attr_id": 630,
"value": 0
},
{
"attr_id": 631,
"value": 0
},
{
"attr_id": 645,
"value": 11.8584
},
{
"attr_id": 646,
"value": 2.5154
},
{
"attr_id": 652,
"value": 0.1751
},
{
"attr_id": 653,
"value": 0.2726
},
{
"attr_id": 654,
"value": 0
},
{
"attr_id": 672,
"value": 0
},
{
"attr_id": 687,
"value": 0
},
{
"attr_id": 689,
"value": 0.0398
},
{
"attr_id": 697,
"value": 0
}
],
"nix_brand_name": null,
"nix_brand_id": null,
"nix_item_name": null,
"nix_item_id": null,
"upc": null,
"consumed_at": "2019-11-12T10:40:37+00:00",
"metadata": {
"is_raw_food": false
},
"source": 1,
"ndb_no": 21398,
"tags": {
"item": "cheeseburger",
"measure": null,
"quantity": "1.0",
"food_group": 8,
"tag_id": 445
},
"alt_measures": [
{
"serving_weight": 199,
"measure": "item",
"seq": 1,
"qty": 1
},
{
"serving_weight": 100,
"measure": "g",
"seq": null,
"qty": 100
},
{
"serving_weight": 28.3495,
"measure": "wt. oz",
"seq": null,
"qty": 1
}
],
"lat": null,
"lng": null,
"meal_type": 1,
"photo": {
"thumb": "https://d2xdmhkmkbyw75.cloudfront.net/445_thumb.jpg",
"highres": "https://d2xdmhkmkbyw75.cloudfront.net/445_highres.jpg",
"is_user_uploaded": false
},
"sub_recipe": null
}
]
}
Here is my Deserialization model and Serialization model so I can put it in my cloud_firestore db:
class Nutritionix {
List<Food> food;
Nutritionix({this.food});
factory Nutritionix.fromJson(Map<String, dynamic> parsedJson) {
var list = parsedJson['foods'] as List;
List<Food> foodList = list.map((i) => Food.fromJson(i)).toList();
return Nutritionix(food: foodList);
}
}
class Food {
String foodName;
double servingQuantity;
double serving_weight;
double calories;
double totalFat;
double saturatedFat;
double cholesterol;
double sodium;
double totalCarbohydrate;
double dietaryFiber;
double sugar;
double protein;
double potassium;
double phospate;
List<Nutrients> nutrients;
Photo photo;
Food(
{this.foodName,
this.servingQuantity,
this.serving_weight,
this.calories,
this.totalFat,
this.saturatedFat,
this.cholesterol,
this.sodium,
this.totalCarbohydrate,
this.dietaryFiber,
this.sugar,
this.protein,
this.potassium,
this.phospate,
this.nutrients,
this.photo});
factory Food.fromJson(Map<String, dynamic> parsedJson) {
var list = parsedJson['full_nutrients'] as List;
List<Nutrients> nutrientsList =
list.map((i) => Nutrients.fromJson(i)).toList();
//TODO: FIX ALL IF NULL AND ADD OTHER SERVING SIZES
return Food(
foodName: parsedJson['food_name'],
servingQuantity: parsedJson['serving_qty'].toDouble(),
serving_weight: parsedJson['serving_weight_grams'] != null
? parsedJson['serving_weight_grams'].toDouble()
: 0,
calories: parsedJson['nf_calories'] != null
? parsedJson['nf_calories'].toDouble()
: 0,
totalFat: parsedJson['nf_total_fat'] != null
? parsedJson['nf_total_fat'].toDouble()
: 0,
saturatedFat: parsedJson['nf_saturated_fat'] != null
? parsedJson['nf_saturated_fat'].toDouble()
: 0,
cholesterol: parsedJson['nf_cholesterol'] != null
? parsedJson['nf_cholesterol'].toDouble()
: 0,
sodium: parsedJson['nf_sodium'] != null
? parsedJson['nf_sodium'].toDouble()
: 0,
totalCarbohydrate: parsedJson['nf_total_carbohydrate'] != null
? parsedJson['nf_total_carbohydrate'].toDouble()
: 0,
dietaryFiber: parsedJson['nf_dietary_fiber'] != null
? parsedJson['nf_dietary_fiber'].toDouble()
: 0,
sugar: parsedJson['nf_sugars'] != null
? parsedJson['nf_sugars'].toDouble()
: 0,
protein: parsedJson['nf_protein'] != null
? parsedJson['nf_protein'].toDouble()
: 0,
potassium: parsedJson['nf_protein'] != null
? parsedJson['nf_potassium'].toDouble()
: 0,
phospate:
parsedJson['nf_p'] != null ? parsedJson['nf_p'].toDouble() : 0,
nutrients: nutrientsList,
photo: Photo.fromJson(parsedJson['photo']));
}
//JSON SERIALIZATION SO I CAN INPUT IT IN MY DB
Map<String, dynamic> toJson() {
return {
"foodName": foodName,
"servingQuantity": servingQuantity,
"serving_weight": serving_weight,
"calories": calories,
"totalFat": totalFat,
"saturatedFat": saturatedFat,
"cholesterol": cholesterol,
"sodium": sodium,
"totalCarbohydrate": totalCarbohydrate,
"dietaryFiber": dietaryFiber,
"sugar": sugar,
"protein": protein,
"potassium": potassium,
"phospate": phospate,
"photo": photo.toJson()
};
}
}
class Nutrients {
int attributeID;
double value;
Nutrients({this.attributeID, this.value});
factory Nutrients.fromJson(Map<String, dynamic> parsedJson) {
return Nutrients(
attributeID: parsedJson['attr_id'],
value: parsedJson['value'].toDouble());
}
}
class Photo {
String thumbnail;
String highRes;
Photo({this.highRes, this.thumbnail});
factory Photo.fromJson(Map<String, dynamic> parsedJson) {
return Photo(
highRes: parsedJson['thumbnail'], thumbnail: parsedJson['thumb']);
}
Map<String, dynamic> toJson(){
return{
"highRes": highRes,
"thumbnail": thumbnail
};
}
}
While here is my code for getting the document(s):
void checkMealsList() async {
final mUserData = Provider.of<UserData>(context);
final userLoggedin = mUserData.mUData;
int index = userLoggedin.length - 1;
List<MealsListData> mealEntry = MealsListData.mealEntry;
print('im inside the checkmealslistfunc');
var breakfastDocument = await Firestore.instance
.collection('users')
.document(mUser.uid)
.collection('food')
.document(DateFormat.yMMMd().format(today))
.collection('Breakfast');
breakfastDocument.getDocuments().then((QuerySnapshot query) {
query.documents.forEach((f) {
print(f.data);
//EDITING THE INDEX OF A LIST GIVEN A CONDITION
var newEntry = mealEntry.firstWhere((id) => id.id == f.data['id'], orElse: null);
if (newEntry!= null){
newEntry.meals = f.data['meals'];
print(newEntry.meals);
newEntry.mealType = f.data['mealType'];
print(newEntry.mealType);
newEntry.nutritionix = Nutritionix.fromJson(f.data['nutritionixData']);
// print('this is ${newEntry.nutritionix.food[0].protein}');
}
});
});//.catchError((onError) => onError);
}
The error I'm getting is this:
E/flutter ( 8204): #3 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter ( 8204): #4 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8204): #5 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter ( 8204): #6 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter ( 8204): #7 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter ( 8204): #8 Future._completeWithValue (dart:async/future_impl.dart:522:5)
E/flutter ( 8204): #9 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
E/flutter ( 8204): #10 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
E/flutter ( 8204): #11 Query.getDocuments (package:cloud_firestore/src/query.dart)
E/flutter ( 8204): <asynchronous suspension>
E/flutter ( 8204): #12 _FitnessAppHomeScreenState.checkMealsList
Is there a problem with my Serialization method? Or should I make a separate deserialization for my Firebase records? Any help would be appreciated! :)
I'm new in Ionic development. I'm having a problem retrieving JSON.
"Failed to load https://api.wh.geniussports.com/v1/basketball/competitions/19816/matcheslive?ak=eebd8ae256142ac3fd24bd2003d28782: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access."
Here's my json format
{
"response": {
"meta": {
"version": 1,
"code": 200,
"status": "success",
"request": "http://api.wh.geniussports.com/v1/basketball/competitions/19816/matcheslive?ak=eebd8ae256142ac3fd24bd2003d28782",
"time": 1528177532,
"count": 10,
"limit": 10
},
"data": [
{
"leagueId": 6,
"matchId": 784470,
"competitionId": 19816,
"venueId": 17386,
"poolNumber": 0,
"roundNumber": "1",
"roundDescription": "",
"matchNumber": 1,
"matchStatus": "COMPLETE",
"matchName": "",
"phaseName": "",
"extraPeriodsUsed": 0,
"matchTime": "2017-11-17 19:30:00",
"matchTimeUTC": "2017-11-17 11:30:00",
"enddate": null,
"timeActual": "2017-11-17 19:45:37",
"timeEndActual": "2017-11-17 21:12:10",
"durationActual": 87,
"temperature": 0,
"attendance": 0,
"duration": 120,
"weather": "",
"twitterHashtag": "",
"liveStream": 1,
"matchType": "REGULAR",
"keywords": "",
"ticketURL": "",
"externalId": "920",
"nextMatchId": 0,
"placeIfWon": 0,
"placeIfLost": 0,
"updated": "2017-11-24 11:04:00",
"linkDetail": "/v1/basketball/matches/784470",
"linkDetailLeague": "/v1/basketball/leagues/6",
"venue": {
"venueId": 17386,
"venueName": "Nanhai Gymnasium",
"venueNameInternational": "",
"venueNickname": "Nanhai Gym",
"venueNicknameInternational": "",
"surfaceName": "",
"locationName": "",
"website": "",
"ticketURL": "",
"externalId": "54",
"linkDetailVenue": "/v1/basketball/venues/17386"
},
"leagueName": "ASEAN Basketball League",
"leagueNameInternational": "",
"competitionName": "2017 ASEAN Basketball League",
"competitionNameInternational": "",
"gsId": "",
"competitors": [
{
"competitorType": "TEAM",
"competitorName": "Singapore Slingers",
"competitorId": 88261,
"linkDetailCompetitor": "/v1/basketball/teams/88261",
"scoreString": "59",
"scoreSecondaryString": "",
"completionStatus": "COMPLETE",
"resultPlacing": 0,
"isDrawn": 0,
"isHomeCompetitor": 0,
"teamId": 88261,
"teamName": "Singapore Slingers",
"teamGsId": null,
"teamNameInternational": "",
"teamNickname": "Singapore Slingers",
"teamNicknameInternational": "",
"teamCode": "",
"teamCodeInternational": "",
"website": "",
"internationalReference": "",
"externalId": "74",
"images": {
"logo": {
"L1": {
"size": "L1",
"height": 600,
"width": 600,
"bytes": 45196,
"url": "http://img.wh.sportingpulseinternational.com/5b71cf0a1af51c8376eda43e6ba5bc22L1.jpg"
},
"M1": {
"size": "M1",
"height": 400,
"width": 400,
"bytes": 25005,
"url": "http://img.wh.sportingpulseinternational.com/5b71cf0a1af51c8376eda43e6ba5bc22M1.jpg"
},
"S1": {
"size": "S1",
"height": 200,
"width": 200,
"bytes": 9180,
"url": "http://img.wh.sportingpulseinternational.com/5b71cf0a1af51c8376eda43e6ba5bc22S1.jpg"
},
"T1": {
"size": "T1",
"height": 75,
"width": 75,
"bytes": 2270,
"url": "http://img.wh.sportingpulseinternational.com/5b71cf0a1af51c8376eda43e6ba5bc22T1.jpg"
}
}
},
"clubId": 62,
"clubGsId": null,
"clubName": "Singapore Slingers",
"clubNameInternational": "",
"linkDetailClub": "/v1/basketball/clubs/62"
},
Below is my loadUser function
loadUser(){
this.http.get('http://api.wh.geniussports.com/v1/basketball/competitions/19816/matcheslive?ak=eebd8ae256142ac3fd24bd2003d28782')
.map(res => res.json())
.subscribe(res => {
this.data = data.results;
console.log(data.results);
}, err => {
console.log(err);
});
}
My main goal is to log the data[] array. Please help me
This is the problem with browser, typically its a security concern not to allow other requests which may lead to XSS attack easily. If only for development I suggest you to install a plugin which will disable in your browser plugin
If for production, then you need to configure your API then do this .
I have a JSON log of my application which contains elements in a nested array form, here is the sample of it:-
{
"msgs": [{
"ts": "2017-09-04T07:07:45.6229372Z",
"tid": 25,
"eid": 1,
"lvl": "Information",
"cat": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"msg": {
"cnt": "Request starting HTTP/1.1 POST http://localhost:20001/Processor text/xml; charset=utf-8 685",
"Protocol": "HTTP/1.1",
"Method": "POST",
"ContentType": "text/xml; charset=utf-8",
"ContentLength": 685,
"Scheme": "http",
"Host": "localhost:20001",
"PathBase": "",
"Path": "/Processor",
"QueryString": ""
}
},
{
"ts": "2017-09-04T07:07:45.6229372Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.Service.ServiceHostMiddleware",
"msg": {
"cnt": "REQ"
},
"data": {
"Headers": {
"Connection": "Keep-Alive",
"Content-Length": "685",
"Content-Type": "text/xml; charset=utf-8",
"Accept-Encoding": "gzip, deflate",
"Expect": "100-continue",
"Host": "localhost:20001",
"SOAPAction": "\"http://servereps.mtxeps.com/TransactionService/SendTransaction\""
}
}
},
{
"ts": "2017-09-04T07:07:45.6239372Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.ProcessorTransactionService",
"msg": {
"cnt": "REQ"
},
"data": {
"Trace": "Aa10031<1C>Ab1<1C>Ac000101<1C>Ad20170616145857<1C>Ae10011<1C>AhVT00009<1C>ArY<1C>Be1812<1C>BfS<1C>BnDB<1C>Bo400296<1C>Bp4803<1C>BqDebit Card<1C>Br16<1C>Da300<1C>Dc0<1C>Dk840<1C>Ga01<1C>Gb1<1C>GfG<1C>GhB/GsF>O<1C>GkOE1<1C>Ia7325980B6B284759<1C>Ib8765432100324A00313<1C>Ic0043<1C>Ig3|1|MX2015-06<1C>IjgnkA7MdNlE2EB1c2B3jlz1G3Kf2U5S3x2H9W6ldIY7QpmlUzYcNHGg==|FFFF987654323D2007CD<1C>Nc5<1C>Oa18"
}
},
{
"ts": "2017-09-04T07:07:45.6249373Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "REQ"
},
"data": {
"request": {
"Version": "1.0",
"Server": {
"LogicalDatacenterId": 0,
"PhysicalDatacenterId": 0,
"UniqueId": "G00008D4F35EDADCD368",
"UniversalTimestamp": "2017-09-04T07:07:45.6249373Z"
},
"State": {
"Status": "InFlight"
},
"Tenant": {
"CompanyNumber": 10031,
"StoreNumber": 1,
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"MerchantNumber": "",
"TerminalId": ""
},
"PointOfInteraction": {
"Client": {
"Type": "OpenEPS",
"CardType": "DB",
"CardName": "Debit Card",
"CommandSequence": "B/GsF>O"
},
"Lane": {
"Type": "Attended",
"Number": 1
},
"Terminal": {
"EMVCapabilities": "FullEMV",
"SerialNumber": "0043"
},
"PointOfSale": {
"ReferenceNumber": "VT00009",
"CashierNumber": "1"
},
"LocalTimestamp": "2017-06-16T14:58:57"
},
"Request": {
"MessageType": {
"Code": 0,
"Name": "Standard"
},
"TenderType": {
"Code": 1,
"Name": "Debit"
},
"TransactionType": {
"Code": 1,
"Name": "Purchase"
},
"EntryMode": "Swiped",
"AuditId": 10011,
"CardType": {
"TenderType": {
"Code": 0,
"Name": "Unknown"
},
"Code": 0,
"Name": "Unknown"
},
"AccountNumberFirstSix": "400296",
"AccountNumberLastFour": "4803",
"AccountNumberLength": 16,
"Card": {
"EncryptedTrack": {
"EncryptionType": "Hardware",
"EncryptionKeySerialNumber": "FFFF987654323D2007CD",
"EncryptedValue": "gnkA7MdNlE2EB1c2B3jlz1G3Kf2U5S3x2H9W6ldIY7QpmlUzYcNHGg=="
},
"EncryptedPIN": {
"EncryptionType": "PassThrough",
"EncryptionKeySerialNumber": "8765432100324A00313",
"EncryptedValue": "7325980B6B284759"
}
},
"Currency": {
"Number": 840
},
"Amount": 3.0,
"CashbackAmount": 0.0,
"AllowPartialAuthorization": true,
"Host": {
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"Values": {
"HostProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"StoreProfileId": 1,
"NumericStateCode": 0,
"AlphaStateCode": "NH",
"CheckAuthService": "3"
}
}
},
"Trace": {
"Path": [{
"Type": "OpenEPS",
"Value": "OE1"
},
{
"NodeId": 0,
"Type": "Gateway",
"Value": "GAT"
},
{
"NodeId": 0,
"ElapsedSeconds": 0.7458587,
"Type": "Tenant",
"Value": "TEN"
}]
}
},
"timeoutInMilliseconds": 45000
}
},
{
"ts": "2017-09-04T07:07:45.6259373Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TenantResolutionClient",
"msg": {
"cnt": "SEND"
},
"data": {
"RequestUri": "http://153.71.66.148:20002/TenantConfigurationService/v1/Resolution",
"Method": "POST",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:45 GMT",
"User-Agent": "ConnectedPayments/1.0",
"x-ms-request-root-id": "6627de44-43a027c7567ddccd",
"x-ms-request-id": "|6627de44-43a027c7567ddccd.1.",
"Request-Id": "|6627de44-43a027c7567ddccd.1.",
"Correlation-Context": "UniqueId=G00008D4F35EDADCD368",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "181"
}
}
},
{
"ts": "2017-09-04T07:07:46.37098Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TenantResolutionClient",
"msg": {
"cnt": "RECV"
},
"data": {
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:46 GMT",
"Transfer-Encoding": "chunked",
"X-Unique-Id": "G00008D4F35EDADCD368",
"X-Node-Id": "0",
"Content-Type": "application/json; charset=utf-8"
}
}
},
{
"ts": "2017-09-04T07:07:46.37098Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "Resolution performed."
},
"data": {
"Response": {
"Content": {
"Company": {
"Number": 10031,
"Name": "Sprouts"
},
"TransactionProfile": {
"TransactionProfileId": 1,
"CompanyNumber": 10031,
"Number": 1000,
"Description": "Transaction Profile 1000"
},
"TransactionValidation": {
"TransactionValidationId": 1,
"TransactionProfileId": 1,
"MessageTypeCode": 0,
"TenderTypeCode": 1,
"TransactionTypeCode": 1,
"CardTypeCode": 0
},
"Store": {
"Number": 1,
"Name": "Store 1",
"QueueLaneNumber": 0
},
"StoreProfile": {
"StoreProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"TransactionProfileId": 1,
"HostTypeCode": 7,
"MerchantNumber": "",
"TerminalId": ""
},
"HostProfile": {
"HostProfileId": 1,
"CompanyNumber": 10031,
"StoreNumber": 1,
"StoreProfileId": 1,
"NumericStateCode": 0,
"AlphaStateCode": "NH",
"CheckAuthService": "3"
}
},
"NodeId": 0,
"StatusCode": 200
},
"ElapsedSeconds": 0.7458587
}
},
{
"ts": "2017-09-04T07:07:46.37198Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TransactionAuthorizationClient",
"msg": {
"cnt": "SEND"
},
"data": {
"RequestUri": "http://ser22vvm211:8082/OrchestrationService/v1/Authorization",
"Method": "POST",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:46 GMT",
"User-Agent": "ConnectedPayments/1.0",
"x-ms-request-root-id": "6627de44-43a027c7567ddccd",
"x-ms-request-id": "|6627de44-43a027c7567ddccd.2.",
"Request-Id": "|6627de44-43a027c7567ddccd.2.",
"Correlation-Context": "UniqueId=G00008D4F35EDADCD368",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "1821"
}
}
},
{
"ts": "2017-09-04T07:07:49.8941815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.SDK.TransactionAuthorizationClient",
"msg": {
"cnt": "RECV"
},
"data": {
"StatusCode": 200,
"ReasonPhrase": "OK",
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:49 GMT",
"Server": "Apache-Coyote/1.1",
"Content-Length": "1672",
"Content-Type": "application/json"
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.TransactionProcessingEngine",
"msg": {
"cnt": "RSP"
},
"data": {
"ResponseTransaction": {
"Version": null,
"Server": {
"LogicalDatacenterId": 0,
"PhysicalDatacenterId": 0,
"TransactionId": 10909,
"UniqueId": "G00008D4F35EDADCD368",
"UniversalTimestamp": "2017-09-04T07:07:45.6249373Z"
},
"State": null,
"Tenant": {
"CompanyNumber": 10031,
"StoreNumber": 1,
"HostType": {
"Code": 7,
"Name": "ProdConcordHC"
},
"MerchantNumber": "",
"TerminalId": ""
},
"PointOfInteraction": {
"Client": {
"Type": "B/GsF>O",
"CardType": "DB",
"CardName": "Debit Card",
"CommandSequence": "B/GsF>O",
"Version": null
},
"Lane": {
"Type": "Attended",
"Number": 1
},
"Terminal": {
"EMVCapabilities": "Contact, ContactlessDisabled",
"Type": null,
"SerialNumber": null,
"EMVKernelVersion": null,
"EMVIdentifierCAPK": null,
"PINCapabilities": null
},
"PointOfSale": {
"CashierNumber": "1",
"ReferenceNumber": null
},
"LocalTimestamp": "2017-06-16T14:58:57",
"LocalTimeZoneOffset": null
},
"Request": {
"MessageType": null,
"EntryMode": null,
"CashbackAmount": 0.00,
"AllowPartialAuthorization": true,
"TenderType": null,
"TransactionType": null,
"ReversalType": null,
"ReferenceId": null,
"AuditId": null,
"AccountNumberFirstSix": null,
"AccountNumberLastFour": null,
"AccountNumberLength": null,
"CardType": null,
"PreviousTransaction": null,
"Card": null,
"Check": null,
"Identification": null,
"Currency": null,
"Amount": null,
"TipAmount": null,
"Host": null
},
"Response": {
"ErrorCode": 96,
"ErrorMessage": "E2G",
"IsApproved": false,
"ResponseCode": "96",
"HostResponseCode": "E2G",
"HostResponseMessage": "EDIT ER:OPT DATA",
"ApprovedAmount": 0.00,
"ApprovedCashbackAmount": 0.0,
"IsApprovedLocally": false,
"AuthorizationCode": null,
"ResponseMessage": null,
"BalanceAmount": null,
"Check": null,
"Currency": null,
"Card": null,
"Host": null
},
"Trace": {
"ElapsedSeconds": 4.2694351,
"Path": [{
"NodeId": 0,
"ElapsedSeconds": 4.2694351,
"Type": "Gateway",
"Value": "GAT"
}]
},
"Queue": null,
"SensitiveData": null,
"PreviousTransaction": null,
"Trace": null
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.GatewayService.ProcessorTransactionService",
"msg": {
"cnt": "RSP"
},
"data": {
"Trace": "Aa10031<1C>Ab1<1C>Ac000101<1C>Ad20170616145857<1C>Ae10011<1C>Af96<1C>ArY<1C>BnDB<1C>BqDebit Card<1C>Db0<1C>Dc0<1C>Ga1<1C>Gb1<1C>GfG<1C>GhB/GsF>O<1C>GkGAT<1C>Jb96<1C>Ka7<1C>MbE2G<1C>Mg0<1C>Nc5<1C>Ya10909<1C>Yb0<1C>YcG00008D4F35EDADCD368"
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"lvl": "Information",
"cat": "NCR.CP.Service.ServiceHostMiddleware",
"msg": {
"cnt": "RSP"
},
"data": {
"Headers": {
"Date": "Mon, 04 Sep 2017 07:07:49 GMT",
"Transfer-Encoding": "chunked",
"Content-Type": "text/xml; charset=utf-8",
"X-Unique-Id": "G00008D4F35EDADCD368",
"X-Node-Id": "0"
}
}
},
{
"ts": "2017-09-04T07:07:49.8951815Z",
"tid": 25,
"eid": 2,
"lvl": "Information",
"cat": "Microsoft.AspNetCore.Hosting.Internal.WebHost",
"msg": {
"cnt": "Request finished in 4272.8738ms 200 text/xml; charset=utf-8",
"ElapsedMilliseconds": 4272.8738,
"StatusCode": 200,
"ContentType": "text/xml; charset=utf-8"
}
}],
"RequestId": "G00008D4F35EDADCD368",
"RequestPath": "/Processor",
"Action": "http://servereps.mtxeps.com/TransactionService/SendTransaction",
"Contract": "NCR.CP.GatewayService.IProcessorTransactionContract",
"OperationName": "SendTransaction",
"MethodName": "SendTransaction"
}
Here "msgs" element contains nested array object into it, so to create field of every elements inside the array object i had followed the mutate and split approach both:-
Mutate filter:-
mutate {
add_field => {
"ts" => "%{[doc][msgs][0][ts]}"
"tid1" => "%{[doc][msgs][0][tid]}"
"eid1" => "%{[doc][msgs][0][eid]}"
"lvl1" => "%{[doc][msgs][0][lvl]}"
"cat1" => "%{[doc][msgs][0][cat]}"
"msg1" => "%{[doc][msgs][0][msg]}"
"data" => "%{[doc][msgs][1][data]}"
"actual-message" =>"%{[doc][msgs][3][data][Trace]}"
"error" =>"%{[doc][msgs][5][ex][exs][0][ec]}"
"error-type" =>"%{[doc][msgs][5][ex][exs][0][typ]}"
}
}
This approach is static as my logs is occurring dynamically i.e position of error is not fixed as it may come in 6th array element or may be at 7th or 8th,
so i ignored this approach and followed the split filter approach:-
Split Filter in logstash config:-
input{
file{
path=>"C:\Logs\GatewayService\GatewayService-Processor.Transactions-20170830.slog"
}
}
split {
field=>"msgs"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "g_index"
}
}
now it is showing error as:
[2017-09-19T17:40:07,557][WARN ][logstash.filters.split ] Only String and Array types are splittable. field:msg is of type = NilClass
so how should i able to retrieve every element in this JSON to be a field so as to visualize in kibana by applying metrics in dashboard.
I have a nested JSON. I want it to be read in pandas in order to explore it, but I got errors. When to use read_json method, I got: "Trailing data". It is valid JSON. How to read it in pd? (Tried differently, but did not work). It looks like this:
{
"contributors": null,
"coordinates": null,
"created_at": "Fri May 26 08:54:00 +0000 2017",
"entities": {
"hashtags": [],
"media": [
{
"display_url": "pic.twitter.com/Pm28ORTePl",
"expanded_url": "",
"id": 868027417121751040,
"id_str": "868027417121751040",
"indices": [
94,
117
],
"media_url": "",
"sizes": {
"large": {
"h": 404,
"resize": "fit",
"w": 773
},
"medium": {
"h": 404,
"resize": "fit",
"w": 773
},
"small": {
"h": 355,
"resize": "fit",
"w": 680
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"type": "photo",
"url": ""
}
],
"symbols": [],
"urls": [
{
"display_url": "",
"expanded_url": "",
"indices": [
70,
93
],
"url": ""
}
],
"user_mentions": []
},
"extended_entities": {
"media": [
{
"display_url": "pic.twitter.com/Pm28ORTePl",
"expanded_url": "1",
"id": 868027417121751040,
"id_str": "868027417121751040",
"indices": [
94,
117
],
"media_url": "",
"media_url_https": "",
"sizes": {
"large": {
"h": 404,
"resize": "fit",
"w": 773
},
"medium": {
"h": 404,
"resize": "fit",
"w": 773
},
"small": {
"h": 355,
"resize": "fit",
"w": 680
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"type": "photo",
"url": ""
}
]
},
"favorite_count": 1,
"favorited": false,
"geo": null,
"id": 868027425757724672,
"id_str": "868027425757724672",
"in_reply_to_screen_name": null,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"is_quote_status": false,
"lang": "ru",
"place": null,
"possibly_sensitive": false,
"retweet_count": 0,
"retweeted": false,
"source": "Twitter Web Client",
"text": "\u041f\u0440\u043e\u043f\u0430\u0432\u0448\u0430\u044f \u0432 \u041a\u043e\u043a\u0448\u0435\u0442\u0430\u0443 \u0448\u043a\u043e\u043b\u044c\u043d\u0438\u0446\u0430 \u0436\u0438\u043b\u0430 \u0432 \u0437\u0430\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u043c \u0434\u043e\u043c\u0435 \u0438 \u0431\u0440\u043e\u0434\u044f\u0436\u043d\u0438\u0447\u0430\u043b\u0430\n",
"truncated": false,
"user": {
"contributors_enabled": false,
"created_at": "Wed May 18 11:59:50 +0000 2011",
"default_profile": true,
"default_profile_image": false,
"description": "\u041a\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043d\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043f\u043e\u0440\u0442\u0430\u043b",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "",
"expanded_url": "",
"indices": [
0,
22
],
"url": ""
}
]
}
},
"favourites_count": 87,
"follow_request_sent": false,
"followers_count": 17989,
"following": true,
"friends_count": 98,
"geo_enabled": true,
"has_extended_profile": false,
"id": 300811189,
"id_str": "300811189",
"is_translation_enabled": false,
"is_translator": false,
"lang": "ru",
"listed_count": 86,
"location": "\u0410\u043b\u043c\u0430\u0442\u044b",
"name": "",
"notifications": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/300811189/1489117916",
"profile_image_url": "http://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
"profile_link_color": "1DA1F2",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"protected": false,
"screen_name": "",
"statuses_count": 53011,
"time_zone": "Quito",
"translator_type": "none",
"url": "",
"utc_offset": -18000,
"verified": false
}
}
Sorry, but your JSON is actually not valid, despite your saying it is.
This line:
"media_url": "": "",
Should probably be:
"media_url": "",
At which point, when I added the final bracket } that was outside of your code block, validated as properly formed JSON.
This is one of the strangest errors I have encountered in a long time.
I have a ServerResponse POJO that I respond with from my Spring MVC REST app using JSON or XML Marshaller configured with ContentNegotiatingViewResolver.
Now my standard JSON response in case of error should look like ->
{ response: { result: null, error: {code: "500", message: "Internal Server Error"}}
and a similar XML.
Instead I'm getting the following in case a Hibernate exception occurs in:
{
"response": {
"result": null,
"error": {
"message": "Internal Server Error",
"code": "500"
},
"respTime": "100 ms"
},
"exception": {
"cause": null,
"message": null,
"localizedMessage": null,
"stackTrace": [(45)
{
"fileName": "NativeConstructorAccessorImpl.java",
"lineNumber": -2,
"className": "sun.reflect.NativeConstructorAccessorImpl",
"methodName": "newInstance0",
"nativeMethod": true
},
{
"fileName": "NativeConstructorAccessorImpl.java",
"lineNumber": 39,
"className": "sun.reflect.NativeConstructorAccessorImpl",
"methodName": "newInstance",
"nativeMethod": false
},
{
"fileName": "DelegatingConstructorAccessorImpl.java",
"lineNumber": 27,
"className": "sun.reflect.DelegatingConstructorAccessorImpl",
"methodName": "newInstance",
"nativeMethod": false
},
{
"fileName": "Constructor.java",
"lineNumber": 513,
"className": "java.lang.reflect.Constructor",
"methodName": "newInstance",
"nativeMethod": false
},
{
"fileName": "BeanUtils.java",
"lineNumber": 147,
"className": "org.springframework.beans.BeanUtils",
"methodName": "instantiateClass",
"nativeMethod": false
},
{
"fileName": "BeanUtils.java",
"lineNumber": 104,
"className": "org.springframework.beans.BeanUtils",
"methodName": "instantiateClass",
"nativeMethod": false
},
{
"fileName": "ModelAttributeMethodProcessor.java",
"lineNumber": 125,
"className": "org.springframework.web.method.annotation.support.ModelAttributeMethodProcessor",
"methodName": "createDataBinder",
"nativeMethod": false
},
{
"fileName": "ModelAttributeMethodProcessor.java",
"lineNumber": 92,
"className": "org.springframework.web.method.annotation.support.ModelAttributeMethodProcessor",
"methodName": "resolveArgument",
"nativeMethod": false
},
{
"fileName": "HandlerMethodArgumentResolverComposite.java",
"lineNumber": 65,
"className": "org.springframework.web.method.support.HandlerMethodArgumentResolverComposite",
"methodName": "resolveArgument",
"nativeMethod": false
},
{
"fileName": "InvocableHandlerMethod.java",
"lineNumber": 153,
"className": "org.springframework.web.method.support.InvocableHandlerMethod",
"methodName": "getMethodArgumentValues",
"nativeMethod": false
},
{
"fileName": "InvocableHandlerMethod.java",
"lineNumber": 117,
"className": "org.springframework.web.method.support.InvocableHandlerMethod",
"methodName": "invokeForRequest",
"nativeMethod": false
},
{
"fileName": "ModelFactory.java",
"lineNumber": 118,
"className": "org.springframework.web.method.annotation.ModelFactory",
"methodName": "invokeAttributeMethods",
"nativeMethod": false
},
{
"fileName": "ModelFactory.java",
"lineNumber": 100,
"className": "org.springframework.web.method.annotation.ModelFactory",
"methodName": "initModel",
"nativeMethod": false
},
{
"fileName": "RequestMappingHandlerAdapter.java",
"lineNumber": 500,
"className": "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter",
"methodName": "invokeHandlerMethod",
"nativeMethod": false
},
{
"fileName": "RequestMappingHandlerAdapter.java",
"lineNumber": 465,
"className": "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter",
"methodName": "handleInternal",
"nativeMethod": false
},
{
"fileName": "AbstractHandlerMethodAdapter.java",
"lineNumber": 80,
"className": "org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter",
"methodName": "handle",
"nativeMethod": false
},
{
"fileName": "DispatcherServlet.java",
"lineNumber": 863,
"className": "org.springframework.web.servlet.DispatcherServlet",
"methodName": "doDispatch",
"nativeMethod": false
},
{
"fileName": "BaseDispatcherServlet.java",
"lineNumber": 31,
"className": "com.locationguru.framework.base.BaseDispatcherServlet",
"methodName": "doDispatch",
"nativeMethod": false
},
{
"fileName": "DispatcherServlet.java",
"lineNumber": 792,
"className": "org.springframework.web.servlet.DispatcherServlet",
"methodName": "doService",
"nativeMethod": false
},
{
"fileName": "BaseDispatcherServlet.java",
"lineNumber": 24,
"className": "com.locationguru.framework.base.BaseDispatcherServlet",
"methodName": "doService",
"nativeMethod": false
},
{
"fileName": "FrameworkServlet.java",
"lineNumber": 851,
"className": "org.springframework.web.servlet.FrameworkServlet",
"methodName": "processRequest",
"nativeMethod": false
},
{
"fileName": "FrameworkServlet.java",
"lineNumber": 767,
"className": "org.springframework.web.servlet.FrameworkServlet",
"methodName": "doPost",
"nativeMethod": false
},
{
"fileName": "HttpServlet.java",
"lineNumber": 641,
"className": "javax.servlet.http.HttpServlet",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "BaseDispatcherServlet.java",
"lineNumber": 38,
"className": "com.locationguru.framework.base.BaseDispatcherServlet",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "HttpServlet.java",
"lineNumber": 722,
"className": "javax.servlet.http.HttpServlet",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "ApplicationFilterChain.java",
"lineNumber": 304,
"className": "org.apache.catalina.core.ApplicationFilterChain",
"methodName": "internalDoFilter",
"nativeMethod": false
},
{
"fileName": "ApplicationFilterChain.java",
"lineNumber": 210,
"className": "org.apache.catalina.core.ApplicationFilterChain",
"methodName": "doFilter",
"nativeMethod": false
},
{
"fileName": "OpenSessionInViewFilter.java",
"lineNumber": 198,
"className": "org.springframework.orm.hibernate3.support.OpenSessionInViewFilter",
"methodName": "doFilterInternal",
"nativeMethod": false
},
{
"fileName": "OncePerRequestFilter.java",
"lineNumber": 76,
"className": "org.springframework.web.filter.OncePerRequestFilter",
"methodName": "doFilter",
"nativeMethod": false
},
{
"fileName": "ApplicationFilterChain.java",
"lineNumber": 243,
"className": "org.apache.catalina.core.ApplicationFilterChain",
"methodName": "internalDoFilter",
"nativeMethod": false
},
{
"fileName": "ApplicationFilterChain.java",
"lineNumber": 210,
"className": "org.apache.catalina.core.ApplicationFilterChain",
"methodName": "doFilter",
"nativeMethod": false
},
{
"fileName": "StandardWrapperValve.java",
"lineNumber": 224,
"className": "org.apache.catalina.core.StandardWrapperValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "StandardContextValve.java",
"lineNumber": 185,
"className": "org.apache.catalina.core.StandardContextValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "AuthenticatorBase.java",
"lineNumber": 472,
"className": "org.apache.catalina.authenticator.AuthenticatorBase",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "StandardHostValve.java",
"lineNumber": 151,
"className": "org.apache.catalina.core.StandardHostValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "ErrorReportValve.java",
"lineNumber": 100,
"className": "org.apache.catalina.valves.ErrorReportValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "AccessLogValve.java",
"lineNumber": 929,
"className": "org.apache.catalina.valves.AccessLogValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "StandardEngineValve.java",
"lineNumber": 118,
"className": "org.apache.catalina.core.StandardEngineValve",
"methodName": "invoke",
"nativeMethod": false
},
{
"fileName": "CoyoteAdapter.java",
"lineNumber": 405,
"className": "org.apache.catalina.connector.CoyoteAdapter",
"methodName": "service",
"nativeMethod": false
},
{
"fileName": "Http11Processor.java",
"lineNumber": 269,
"className": "org.apache.coyote.http11.Http11Processor",
"methodName": "process",
"nativeMethod": false
},
{
"fileName": "AbstractProtocol.java",
"lineNumber": 515,
"className": "org.apache.coyote.AbstractProtocol$AbstractConnectionHandler",
"methodName": "process",
"nativeMethod": false
},
{
"fileName": "JIoEndpoint.java",
"lineNumber": 300,
"className": "org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 886,
"className": "java.util.concurrent.ThreadPoolExecutor$Worker",
"methodName": "runTask",
"nativeMethod": false
},
{
"fileName": "ThreadPoolExecutor.java",
"lineNumber": 908,
"className": "java.util.concurrent.ThreadPoolExecutor$Worker",
"methodName": "run",
"nativeMethod": false
},
{
"fileName": "Thread.java",
"lineNumber": 680,
"className": "java.lang.Thread",
"methodName": "run",
"nativeMethod": false
}
]
}
}
While the XML is still coming out correctly.
Any Ideas?
The following configuration while Jackson Json Marshaller bean helped remove the unncessary keys getting rendered in my JSON response.
<!-- XStream XML View -->
<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="autodetectAnnotations" value="true"/>
<property name="annotatedClasses">
<list>
<value>framework.response.object.ServerResponse</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
</list>
</property>
<property name="defaultContentType" value="application/xml"/>
<property name="favorPathExtension" value="true"/>
</bean>
Focus Here -->
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="modelKey" value="response" />
</bean>