spring4 下jackson的配置

 

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

 

 

 

 

 

spring从3.1升级到4.1.3 json 处理失败

报出以上错误。

 

 

折腾了半天 最终找到解决办法 

spring 配置

 

      
      
          
              
              
                  
                      
                        application/json;charset=UTF-8  
                        text/html;charset=UTF-8  
                      
                  
              
          
      


pom 使用

 

 

 


		
			com.fasterxml.jackson.core
			jackson-databind
			 2.6.3
		 
		 
		    com.fasterxml.jackson.core
		    jackson-core
				 2.6.3
		
		
		    com.fasterxml.jackson.core
		    jackson-annotations
		    	 2.6.0
		


java 调用

 

 

	@RequestMapping(value = "login"  , method = RequestMethod.GET ) //, method = RequestMethod.GET
	@ResponseBody
	public 	 Map loginuser(@Valid INLoginUser inLoginUser) throws JsonProcessingException{ // @Uid String uid
		//int count = userService.modifyPassword(onlineUser.getUserId(), oldPwd, newPwd);
		Map personalLogin = userService.loginNew(inLoginUser.getUsername(), inLoginUser.getPassword());
		OnlineUser user = (OnlineUser) personalLogin.get("onlineUser");
		if (user != null) {
			Long token = user.getUserId()*31+12345 ;
			Map returnMap = new HashMap();
			returnMap.put("token", token);
			returnMap.put("user", user);
			return Ajax.getSuccessReturnMapWithData(returnMap);
		} else {
			String error = (String) personalLogin.get("error");
			return Ajax.buildErrorResult(error);
		}
	}

 

参考 :https://my.oschina.net/u/2273085/blog/476790

spring4 下jackson的配置_第1张图片

你可能感兴趣的:(spring,web,server)