public void testPrettyPrinter() throws Exception { PrettyPrinter p = new DefaultPrettyPrinter(); byte[] stuff = jdkSerialize(p); PrettyPrinter back = jdkDeserialize(stuff); // what should we test? assertNotNull(back); }
protected ObjectWriter(ObjectMapper paramObjectMapper, SerializationConfig paramSerializationConfig, JavaType paramJavaType, PrettyPrinter paramPrettyPrinter) { this._config = paramSerializationConfig; this._serializerProvider = paramObjectMapper._serializerProvider; this._serializerFactory = paramObjectMapper._serializerFactory; this._jsonFactory = paramObjectMapper._jsonFactory; if (paramJavaType != null) paramJavaType = paramJavaType.withStaticTyping(); this._rootType = paramJavaType; this._prettyPrinter = paramPrettyPrinter; this._schema = null; this._rootSerializer = _prefetchRootSerializer(paramSerializationConfig, paramJavaType); }
protected ObjectWriter(ObjectWriter paramObjectWriter, SerializationConfig paramSerializationConfig, JavaType paramJavaType, JsonSerializer<Object> paramJsonSerializer, PrettyPrinter paramPrettyPrinter, FormatSchema paramFormatSchema) { this._config = paramSerializationConfig; this._serializerProvider = paramObjectWriter._serializerProvider; this._serializerFactory = paramObjectWriter._serializerFactory; this._jsonFactory = paramObjectWriter._jsonFactory; this._rootType = paramJavaType; this._rootSerializer = paramJsonSerializer; this._prettyPrinter = paramPrettyPrinter; this._schema = paramFormatSchema; }
public ObjectWriter with(PrettyPrinter paramPrettyPrinter) { if (paramPrettyPrinter == this._prettyPrinter) return this; if (paramPrettyPrinter == null) paramPrettyPrinter = NULL_PRETTY_PRINTER; SerializationConfig localSerializationConfig = this._config; JavaType localJavaType = this._rootType; JsonSerializer localJsonSerializer = this._rootSerializer; FormatSchema localFormatSchema = this._schema; return new ObjectWriter(this, localSerializationConfig, localJavaType, localJsonSerializer, paramPrettyPrinter, localFormatSchema); }
@Nullable private String initStructure(CanvasSessionData data, SelectionSession session, SingleSignonForm form) { final String courseId = data.getCourseId(); String structure = form.getStructure(); if( structure == null ) { // if course ID is empty then there is nothing we can do... if( Strings.isNullOrEmpty(courseId) ) { throw new RuntimeException(LABEL_ERROR_NO_COURSE.getText()); } structure = courseStructureCache.get(courseId).orNull(); } // if no structure, get from Canvas if( structure == null ) { final ObjectNode root = objectMapper.createObjectNode(); root.put("id", courseId); root.put("name", data.getContextTitle()); root.put("targetable", false); final ArrayNode foldersNode = objectMapper.createArrayNode(); root.put("folders", foldersNode); final Connector connector = findConnector(data); final List<ConnectorFolder> folders = connectorRepoService.getFoldersForCourse(connector, CurrentUser.getUsername(), courseId, false); boolean first = true; for( ConnectorFolder folder : folders ) { final ObjectNode folderNode = objectMapper.createObjectNode(); folderNode.put("id", folder.getId()); folderNode.put("name", folder.getName()); folderNode.put("targetable", true); folderNode.put("defaultFolder", first); foldersNode.add(folderNode); first = false; } final PrettyPrinter pp = new MinimalPrettyPrinter(); try { structure = objectMapper.writer().with(pp).writeValueAsString(root); } catch( JsonProcessingException e ) { throw Throwables.propagate(e); } } if( structure != null ) { courseStructureCache.put(courseId, structure); } return structure; }
private String getStructure(String courseId, String connectorUuid, String selected) { try { final boolean isDefaultApplicable = !Strings.isNullOrEmpty(selected); final String cacheKey = connectorUuid + ":" + courseId + (!isDefaultApplicable ? "" : ":" + selected); String structure = courseStructureCache.get(cacheKey).orNull(); // if no structure, get from Brightspace if( structure == null ) { final Connector connector = connectorService.getByUuid(connectorUuid); if( connector == null ) { throw new RuntimeException("No connector with UUID = " + connectorUuid); } final ConnectorCourse course = brightspaceService.getCourse(connector, courseId); final ObjectNode root = objectMapper.createObjectNode(); root.put("id", courseId); root.put("name", course.getName()); root.put("targetable", false); final ArrayNode foldersNode = objectMapper.createArrayNode(); root.put("folders", foldersNode); final List<ConnectorFolder> folders = brightspaceService.getFoldersForCourse(connector, null, courseId, false); boolean first = true; for( ConnectorFolder folder : folders ) { final ObjectNode folderNode = objectMapper.createObjectNode(); folderNode.put("id", folder.getId()); folderNode.put("name", folder.getName()); folderNode.put("targetable", true); folderNode.put("selected", (!isDefaultApplicable && first) || (isDefaultApplicable && selected.equals(folder.getId()))); foldersNode.add(folderNode); first = false; recurseFolder(connector, courseId, folder, folderNode, selected); } final PrettyPrinter pp = new MinimalPrettyPrinter(); try { structure = objectMapper.writer().with(pp).writeValueAsString(root); } catch( JsonProcessingException e ) { throw Throwables.propagate(e); } if( structure == null ) { // Can't happen throw new RuntimeException("Could not create structure"); } courseStructureCache.put(cacheKey, structure); } return structure; } catch( LmsUserNotFoundException lms ) { throw Throwables.propagate(lms); } }
private MessageMarshaller(@Nullable PrettyPrinter prettyPrinter, MarshallerRegistry registry) { this.prettyPrinter = prettyPrinter; this.registry = registry; }
public void setPrettyPrinter(PrettyPrinter prettyPrinter) { this.prettyPrinter = prettyPrinter; }
public PrettyPrinter getPrettyPrinter() { return this.delegate.getPrettyPrinter(); }
public JsonGenerator setPrettyPrinter(PrettyPrinter paramPrettyPrinter) { this.delegate.setPrettyPrinter(paramPrettyPrinter); return this; }
public static PrettyPrinter getPrettyPrinter() { CustomPrettyPrinter prettyPrinter = new CustomPrettyPrinter(); prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE); return prettyPrinter; }
public PrettyPrinter getPrettyPrinter() { return _prettyPrinter; }
public void setPrettyPrinter(PrettyPrinter prettyPrinter) { _prettyPrinter = prettyPrinter; }
@Override protected PrettyPrinter newCompactPrinter() { return new MinimalPrettyPrinter(); }
@Override protected PrettyPrinter newPrettyPrinter() { return new DefaultPrettyPrinter(); }
@Override protected PrettyPrinter newCompactPrinter() { // Yes, null is the proper answer. return null; }
@Override protected PrettyPrinter newPrettyPrinter() { return new Log4jXmlPrettyPrinter(DEFAULT_INDENT); }
/** * Instantiates a new Registered service json serializer. * * @param prettyPrinter the pretty printer */ public AbstractJacksonBackedJsonSerializer(final PrettyPrinter prettyPrinter) { this.objectMapper = initializeObjectMapper(); this.prettyPrinter = prettyPrinter; }
/** * Instantiates a new Registered service json serializer. * * @param objectMapper the object mapper * @param prettyPrinter the pretty printer */ public AbstractJacksonBackedJsonSerializer(final ObjectMapper objectMapper, final PrettyPrinter prettyPrinter) { this.objectMapper = objectMapper; this.prettyPrinter = prettyPrinter; }
/** * Instantiates a new Registered service json serializer. * * @param prettyPrinter the pretty printer */ public AbstractJacksonBackedStringSerializer(final PrettyPrinter prettyPrinter) { this.objectMapper = initializeObjectMapper(); this.prettyPrinter = prettyPrinter; }
/** * Instantiates a new Registered service json serializer. * * @param objectMapper the object mapper * @param prettyPrinter the pretty printer */ public AbstractJacksonBackedStringSerializer(final ObjectMapper objectMapper, final PrettyPrinter prettyPrinter) { this.objectMapper = objectMapper; this.prettyPrinter = prettyPrinter; }
/** * Sets the pretty printer to pretty-print the JSON with. Note that this * method implicitly enables indenting, so {@code setPrettyPrint(true)} does * not also need to be called. * @param prettyPrinter the custom pretty printer (defaults to an instance * of {@link JCalPrettyPrinter}, if {@code setPrettyPrint(true)} has been * called) */ public void setPrettyPrinter(PrettyPrinter prettyPrinter) { prettyPrint = true; this.prettyPrinter = prettyPrinter; }
/** * This method behaves similarly to the <code>writeValueAsString(Object value)</code> method * except that it includes an indentation prefix that will be prepended to each line of the * resulting string (except the first line). * * @param value The smart object to be written out as a string. * @param indentation The indentation string to be prepended to each line. * @return The formatted string. * @throws JsonProcessingException The JSON object mapper was not able to serialize the object. */ String writeValueAsString(Object value, String indentation) throws JsonProcessingException { PrettyPrinter printer = new BetterPrettyPrinter(indentation).withArrayIndenter(new DefaultIndenter()); return writer(printer).writeValueAsString(value); }
abstract protected PrettyPrinter newCompactPrinter();
abstract protected PrettyPrinter newPrettyPrinter();