Example usage for javax.websocket EncodeException EncodeException

List of usage examples for javax.websocket EncodeException EncodeException

Introduction

In this page you can find the example usage for javax.websocket EncodeException EncodeException.

Prototype

public EncodeException(Object object, String message) 

Source Link

Usage

From source file:ws.util.AbstractJSONCoder.java

@Override
public String encode(T pojo) throws EncodeException {
    StringBuilder log = new StringBuilder().append(type).append("| [coder] encoding..").append(pojo);
    String json = null;/*from  w  ww  . j a  va 2s .c o m*/
    try {
        ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
        // Jackson jr ??@JsonManagedReference, @JsonBackReference????
        //                  json = JSON.std.asString(pojo);
        json = ow.writeValueAsString(pojo);
        log.append(" DONE.");
    } catch (IOException e) {
        log.append(" **NG**.");
        logger.log(Level.SEVERE, e.toString());
        e.printStackTrace();
        throw new EncodeException(json, e.getMessage());
    } catch (Exception e) {
        log.append(" **NG**.");
        logger.log(Level.SEVERE, e.toString());
        e.printStackTrace();
        throw new EncodeException(json, e.getMessage());
    } finally {
        logger.log(Level.INFO, log.toString());
    }
    //            logger.log(Level.INFO, new StringBuilder()
    //                  .append("[coder] done: ")
    //                  .append(json)
    //                  .toString());
    return json;
}