use of com.fasterxml.jackson.databind.ObjectMapper in project keywhiz by square.
the class CliModule method generalMapper.
@Provides
public ObjectMapper generalMapper() {
/**
* Customizes ObjectMapper for common settings.
*
* @param objectMapper to be customized
* @return customized input factory
*/
ObjectMapper objectMapper = Jackson.newObjectMapper();
objectMapper.registerModule(new Jdk8Module());
objectMapper.registerModules(new JavaTimeModule());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return objectMapper;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project android-async-http by loopj.
the class CustomCASample method getResponseHandler.
@Override
public ResponseHandlerInterface getResponseHandler() {
return new BaseJsonHttpResponseHandler<SampleJSON>() {
@Override
public void onStart() {
clearOutputs();
}
@Override
public void onSuccess(int statusCode, Header[] headers, String rawJsonResponse, SampleJSON response) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
if (response != null) {
debugResponse(LOG_TAG, rawJsonResponse);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, String rawJsonData, SampleJSON errorResponse) {
debugHeaders(LOG_TAG, headers);
debugStatusCode(LOG_TAG, statusCode);
debugThrowable(LOG_TAG, throwable);
if (errorResponse != null) {
debugResponse(LOG_TAG, rawJsonData);
}
}
@Override
protected SampleJSON parseResponse(String rawJsonData, boolean isFailure) throws Throwable {
return new ObjectMapper().readValues(new JsonFactory().createParser(rawJsonData), SampleJSON.class).next();
}
};
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class ConnectorMojo method updateVersionInCamelConnectorJSon.
private void updateVersionInCamelConnectorJSon(String qualifier, String version) throws MojoExecutionException {
File file = new File(classesDirectory, "camel-connector.json");
if (file.exists()) {
try {
ObjectMapper mapper = new ObjectMapper();
Map dto = mapper.readValue(file, Map.class);
if (version != null) {
String existingVersion = (String) dto.get(qualifier);
if (existingVersion == null || !existingVersion.equals(version)) {
dto.put(qualifier, version);
// update file
mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto);
// project root folder
File root = classesDirectory.getParentFile().getParentFile();
// update source file also
file = new File(root, "src/main/resources/camel-connector.json");
if (file.exists()) {
getLog().info("Updating " + qualifier + " to " + version + " in " + file);
mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto);
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error in camel-connector-maven-plugin", e);
}
}
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class ConnectorMojo method createArchive.
@Override
public File createArchive() throws MojoExecutionException {
// project root folder
File root = classesDirectory.getParentFile().getParentFile();
String gitUrl = null;
// find the component dependency and get its .json file
File file = new File(classesDirectory, "camel-connector.json");
if (file.exists()) {
// updating to use correct project version in camel-connector.json
String version = getProject().getVersion();
updateVersionInCamelConnectorJSon("version", version);
try {
ObjectMapper mapper = new ObjectMapper();
Map dto = mapper.readValue(file, Map.class);
if (includeGitUrl) {
gitUrl = embedGitUrlInCamelConnectorJSon(mapper, dto);
}
File schema = embedCamelComponentSchema(file);
if (schema != null) {
String json = FileHelper.loadText(new FileInputStream(schema));
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
String header = buildComponentHeaderSchema(rows, dto, gitUrl);
getLog().debug(header);
rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
String componentOptions = buildComponentOptionsSchema(rows, dto);
getLog().debug(componentOptions);
rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
String endpointOptions = buildEndpointOptionsSchema(rows, dto);
getLog().debug(endpointOptions);
// generate the json file
StringBuilder jsonSchema = new StringBuilder();
jsonSchema.append("{\n");
jsonSchema.append(header);
jsonSchema.append(componentOptions);
jsonSchema.append(endpointOptions);
jsonSchema.append("}\n");
String newJson = jsonSchema.toString();
// parse ourselves
rows = JSonSchemaHelper.parseJsonSchema("component", newJson, false);
String newScheme = getOption(rows, "scheme");
// write the json file to the target directory as if camel apt would do it
String javaType = (String) dto.get("javaType");
String dir = javaType.substring(0, javaType.lastIndexOf("."));
dir = dir.replace('.', '/');
File subDir = new File(classesDirectory, dir);
String name = newScheme + ".json";
File out = new File(subDir, name);
FileOutputStream fos = new FileOutputStream(out, false);
fos.write(newJson.getBytes());
fos.close();
// also write the file in the root folder so its easier to find that for tooling
out = new File(classesDirectory, "camel-connector-schema.json");
fos = new FileOutputStream(out, false);
fos.write(newJson.getBytes());
fos.close();
if (generateToSources) {
// copy the file into the sources as well
File from = new File(classesDirectory, "camel-connector-schema.json");
File to = new File(root, "src/main/resources/camel-connector-schema.json");
FileHelper.copyFile(from, to);
}
}
// build json schema for component that only has the selectable options
} catch (Exception e) {
throw new MojoExecutionException("Error in camel-connector-maven-plugin", e);
}
}
return super.createArchive();
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class ZooKeeperGroup method close.
/**
* Close/end the cache
*
* @throws IOException errors
*/
@Override
public void close() throws IOException {
LOG.debug(this + ".close, connected:" + connected);
if (started.compareAndSet(true, false)) {
client.getConnectionStateListenable().removeListener(connectionStateListener);
executorService.shutdownNow();
try {
executorService.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException().initCause(e);
}
try {
doUpdate(null);
if (isConnected()) {
callListeners(GroupListener.GroupEvent.DISCONNECTED);
}
} catch (Exception e) {
handleException(e);
}
listeners.clear();
mapper.getTypeFactory().clearCache();
mapper = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
client.clearWatcherReferences(childrenWatcher);
client.clearWatcherReferences(dataWatcher);
}
}
Aggregations