java - JSON Parsing Error - Unable to update core database values -
i using jax-rs on angularjs, have hit stumbling block due json parsing errors.
using jsonlint can see issues, cannot update underlying database values causing issue correct characters (corporate data warehouse)...i in trouble can't return data @ application because small handful of records have non compliant characters in them.
what general approach dealing these kind of issues? search , replace non ascii- characters @ java end in setter?
update:
error chrome:
syntaxerror: unexpected token @ object.parse (native) @ ub (http://localhost:8080/misf-web/lib/angular/angular.min.js:13:122) @ e.defaults.transformresponse (http://localhost:8080/misf-web/lib/angular/angular.min.js:98:83) @ http://localhost:8080/misf-web/lib/angular/angular.min.js:97:347 @ array.foreach (native) @ n (http://localhost:8080/misf-web/lib/angular/angular.min.js:6:470) @ yb (http://localhost:8080/misf-web/lib/angular/angular.min.js:97:329) @ c (http://localhost:8080/misf-web/lib/angular/angular.min.js:99:14) @ (http://localhost:8080/misf-web/lib/angular/angular.min.js:79:437) @ http://localhost:8080/misf-web/lib/angular/angular.min.js:80:485 angular.min.js:63 (anonymous function)
sample json output - 1 example causing me issues...it not "umlauts"...
{ "approvedpriority": "approved", "disease": "primary sj�grens syndrome", "diseasearea": "inflammation", "projecttype": "nme", "therapyarea": "ri" }
in database disease appears "primary sjögren’s syndrome"
jsonlint reports:
parse error on line 3: ...ed", "disease": "primary sj�grens s ----------------------^ expecting 'string', 'number', 'null', 'true', 'false', '{', '['
it not "umlauts" causing me issues, non printable charachter seems, , 1 odd error hunted down due appears wider hyphen normal.
update:
as far aware requesting utf-8 via jax-rs.
@get @path("/projects") @produces(mediatype.application_json + "; charset=utf-8") public list<project> getallprojects() { logger.debug("get: list projects"); return projectservice.getallprojects(); }
i developing on tomcat 7 on windows using eclipse.
seems @produces , adding charset=utf-8 doesn't work.
in end created filter added charset=utf=8 response header before sent , registered provider jersey through application config class.
now works , data being returned perfectly.
why @produces doesn't work mystery.
package com.mycompany.misf.filters;
import javax.ws.rs.container.containerrequestcontext; import javax.ws.rs.container.containerresponsecontext; import javax.ws.rs.container.containerresponsefilter; import javax.ws.rs.core.mediatype; public class headerresponsefilter implements containerresponsefilter { public void filter(containerrequestcontext request, containerresponsecontext response) { mediatype type = response.getmediatype(); if (type != null) { string contenttype = type.tostring(); if (!contenttype.contains("charset")) { contenttype = contenttype + ";charset=utf-8"; response.getheaders().putsingle("content-type", contenttype); } } } }
register filter provider.
@applicationpath("resources") public class restapplication extends resourceconfig { public restapplication() { hashset<class<?>> c = new hashset<class<?>>(); c.add(personsrestservice.class); c.add(projectsrestservice.class); //add c.add(headerresponsefilter.class); set<class<?>> classes = collections.unmodifiableset(c); registerclasses(classes); property(serverproperties.bv_send_error_in_response, true); } }
Comments
Post a Comment