Advertisement
aminusia

Entity Mapper

Sep 3rd, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1.     /**
  2.      * Convert Google Datastore Entity into Json String. Each serialization failure results in
  3.      * dispatch of error status and message to user.
  4.      * @param   entity  The Google Datastore Entity to be serialized
  5.      * @return  String  Json string representation of the entity
  6.      */
  7.     protected String toEntityMapString(Entity entity){
  8.         String result = "";
  9.        
  10.         try{
  11.             result = new ObjectMapper().writeValueAsString(entity.getProperties());
  12.         }catch(JsonMappingException e){
  13.             e.printStackTrace();
  14.             databaseListener.OnQueryFinished("{\"status\":\"error\",message:\"Entity mapping failed (at com.artlogic.defaultserver.db.DBUser:toEntityMapString)\"}");
  15.         } catch (JsonGenerationException e) {
  16.             e.printStackTrace();
  17.             databaseListener.OnQueryFinished("{\"status\":\"error\",message:\"Json string generation failed (at com.artlogic.defaultserver.db.DBUser:toEntityMapString)\"}");
  18.         } catch (IOException e) {
  19.             e.printStackTrace();
  20.             databaseListener.OnQueryFinished("{\"status\":\"error\",message:\"IO exception raised (at com.artlogic.defaultserver.db.DBUser:toEntityMapString)\"}");
  21.         }
  22.        
  23.         return result;
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement