本文整理汇总了Java中org.codehaus.jackson.map.JsonMappingException类的典型用法代码示例。如果您正苦于以下问题:Java JsonMappingException类的具体用法?Java JsonMappingException怎么用?Java JsonMappingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonMappingException类属于org.codehaus.jackson.map包,在下文中一共展示了JsonMappingException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public String build(String script) throws JsonParseException, JsonMappingException, IOException{
//if no dependencies just return itself.
if(!script.contains(IMPORT_PREFIX)){
return script;
}
//add the initial script.
sb.append(script);
//build the set of dependencies.
this.resolveDependencies(script);
//with all the script files build one big script.
for(String path : this.dependencies){
sb.append(this.resolveScript(path));
sb.append("\n\n");
}
return sb.toString();
}
示例2: fromResource
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
/**
* Convert from a JSON file
* @param resource input file
* @return the parsed JSON
* @throws IOException IO problems
* @throws JsonMappingException failure to map from the JSON to this class
*/
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed"})
public synchronized T fromResource(String resource)
throws IOException, JsonParseException, JsonMappingException {
InputStream resStream = null;
try {
resStream = this.getClass().getResourceAsStream(resource);
if (resStream == null) {
throw new FileNotFoundException(resource);
}
return mapper.readValue(resStream, classType);
} catch (IOException e) {
LOG.error("Exception while parsing json resource {}: {}", resource, e);
throw e;
} finally {
IOUtils.closeStream(resStream);
}
}
示例3: processHttpRequest
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public static <T, R> R processHttpRequest(String completeURL,
Class<R> responseType,
T request,
Map<String, String> headers,
HttpMethod method) {
final Map<String, Object> parameters = getParams(request);
try {
return mapper.readValue(
processHttpRequest(completeURL,
parameters,
headers,
method),
responseType);
} catch (JsonParseException | JsonMappingException je) {
throw new ServiceException(CommonExceptionCodes.HTTP_CLIENT_EXCEPTION.code(),
"Could not parse response into specified response type. " + "Error: " + je);
} catch (IOException ioe) {
throw new InternalServerException();
}
}
示例4: testBucketCache
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
@Test
public void testBucketCache() throws JsonGenerationException, JsonMappingException, IOException {
this.conf.set(HConstants.BUCKET_CACHE_IOENGINE_KEY, "offheap");
this.conf.setInt(HConstants.BUCKET_CACHE_SIZE_KEY, 100);
CacheConfig cc = new CacheConfig(this.conf);
assertTrue(cc.getBlockCache() instanceof CombinedBlockCache);
logPerBlock(cc.getBlockCache());
final int count = 3;
addDataAndHits(cc.getBlockCache(), count);
// The below has no asserts. It is just exercising toString and toJSON code.
LOG.info(cc.getBlockCache().getStats());
BlockCacheUtil.CachedBlocksByFile cbsbf = logPerBlock(cc.getBlockCache());
LOG.info(cbsbf);
logPerFile(cbsbf);
bucketCacheReport(cc.getBlockCache());
LOG.info(BlockCacheUtil.toJSON(cbsbf));
}
示例5: testLruBlockCache
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
@Test
public void testLruBlockCache() throws JsonGenerationException, JsonMappingException, IOException {
CacheConfig cc = new CacheConfig(this.conf);
assertTrue(cc.isBlockCacheEnabled());
assertTrue(CacheConfig.DEFAULT_IN_MEMORY == cc.isInMemory());
assertTrue(cc.getBlockCache() instanceof LruBlockCache);
logPerBlock(cc.getBlockCache());
addDataAndHits(cc.getBlockCache(), 3);
// The below has no asserts. It is just exercising toString and toJSON code.
BlockCache bc = cc.getBlockCache();
LOG.info("count=" + bc.getBlockCount() + ", currentSize=" + bc.getCurrentSize() +
", freeSize=" + bc.getFreeSize() );
LOG.info(cc.getBlockCache().getStats());
BlockCacheUtil.CachedBlocksByFile cbsbf = logPerBlock(cc.getBlockCache());
LOG.info(cbsbf);
logPerFile(cbsbf);
bucketCacheReport(cc.getBlockCache());
LOG.info(BlockCacheUtil.toJSON(cbsbf));
}
示例6: logPerFile
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
private void logPerFile(final BlockCacheUtil.CachedBlocksByFile cbsbf)
throws JsonGenerationException, JsonMappingException, IOException {
for (Map.Entry<String, NavigableSet<CachedBlock>> e:
cbsbf.getCachedBlockStatsByFile().entrySet()) {
int count = 0;
long size = 0;
int countData = 0;
long sizeData = 0;
for (CachedBlock cb: e.getValue()) {
count++;
size += cb.getSize();
BlockType bt = cb.getBlockType();
if (bt != null && bt.isData()) {
countData++;
sizeData += cb.getSize();
}
}
LOG.info("filename=" + e.getKey() + ", count=" + count + ", countData=" + countData +
", size=" + size + ", sizeData=" + sizeData);
LOG.info(BlockCacheUtil.toJSON(e.getKey(), e.getValue()));
}
}
示例7: output
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public void output(Map<String, Object> parameters, boolean withRequest, boolean prettyPrint)
throws JsonGenerationException, JsonMappingException, IOException {
Map<String, Object> result = new LinkedHashMap<String, Object>();
// put request to result
if (withRequest) {
Map<String, Object> request = new LinkedHashMap<String, Object>();
request.put("command", getName());
request.put("parameters", parameters);
result.put("request", request);
}
// put response to result
putResponse("status", getStatus());
putResponse("message", getMessage());
result.put("response", getResponse());
ObjectMapper mapper = new ObjectMapper();
if (prettyPrint) {
// enable pretty print
System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(result));
} else {
System.out.println(mapper.writeValueAsString(result));
}
}
示例8: readList
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
/**
* Reads a collection of FileTrackingStatus.<br/>
* If plain text is a list of line separated plain text.<br/>
* If json this should be a json array.<br/>
*
* @param format
* @param reader
* @return
* @throws JsonParseException
* @throws JsonMappingException
* @throws IOException
*/
@SuppressWarnings("unchecked")
public Collection<FileTrackingStatus> readList(FORMAT format, Reader reader)
throws JsonParseException, JsonMappingException, IOException {
Collection<FileTrackingStatus> coll = null;
if (format.equals(FORMAT.JSON)) {
coll = (Collection<FileTrackingStatus>) mapper.readValue(reader,
new TypeReference<Collection<FileTrackingStatus>>() { });
} else {
BufferedReader buff = new BufferedReader(reader);
coll = new ArrayList<FileTrackingStatus>();
String line = null;
while ((line = buff.readLine()) != null) {
coll.add(read(FORMAT.TXT, line));
}
}
return coll;
}
示例9: CommandImpl
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public CommandImpl(Long id, IPolicy policy, ITask task, List<String> dnList, DNType dnType, List<String> uidList,
String commandOwnerUid, Date activationDate, Date expirationDate, Date createDate,
List<CommandExecutionImpl> commandExecutions, boolean sentMail)
throws JsonGenerationException, JsonMappingException, IOException {
this.id = id;
this.policy = (PolicyImpl) policy;
this.task = (TaskImpl) task;
ObjectMapper mapper = new ObjectMapper();
this.dnListJsonString = mapper.writeValueAsString(dnList);
setDnType(dnType);
this.uidListJsonString = uidList != null ? mapper.writeValueAsString(uidList) : null;
this.commandOwnerUid = commandOwnerUid;
this.activationDate = activationDate;
this.expirationDate = expirationDate;
this.createDate = createDate;
this.commandExecutions = commandExecutions;
this.sentMail = sentMail;
}
示例10: resolveDependencies
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public void resolveDependencies(String script) throws JsonParseException, JsonMappingException, IOException{
String[] parsed = script.split("\n");
for(String str : parsed){
if(str.contains(IMPORT_PREFIX)){
str = StrUtils.rightBack(str, IMPORT_PREFIX);
String[] references = str.split(StringCache.COMMA);
for(String path : references){
path = path.trim();
if(!dependencies.contains(path)){
dependencies.add(path);
String newScript = this.resolveScript(path);
//recurse to pull in all the script files.
this.resolveDependencies(newScript);
}
}
}
}
}
示例11: createDocument
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public static SolrInputDocument createDocument(String dataStr)
throws JsonParseException, JsonMappingException, IOException {
Map<String, Object> dataMap =
new ObjectMapper().readValue(dataStr, new TypeReference<HashMap<String, Object>>() {
});
SolrInputDocument document = new SolrInputDocument();
for (Iterator<String> i = dataMap.keySet().iterator(); i.hasNext();) {
String fieldName = i.next();
Object fieldValue = dataMap.get(fieldName);
document.addField(fieldName, fieldValue);
}
return document;
}
示例12: testCreateDocument
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
public void testCreateDocument() throws JsonParseException, JsonMappingException, IOException {
String data =
"{\"id\":\"1\",\"title_txt_en\":\"SolrJ\",\"description_txt_en\":\"SolrJ is an API that makes it easy for Java applications to talk to Solr.\"}";
SolrInputDocument document = SolrJExampleUtil.createDocument(data);
String expectedId = "1";
String actualId = document.getFieldValue("id").toString();
assertEquals(expectedId, actualId);
String expectedTitle = "SolrJ";
String actualTitle = document.getFieldValue("title_txt_en").toString();
assertEquals(expectedTitle, actualTitle);
String expectedDescription =
"SolrJ is an API that makes it easy for Java applications to talk to Solr.";
String actualDescription = document.getFieldValue("description_txt_en").toString();
assertEquals(expectedDescription, actualDescription);
}
示例13: mapException
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Status mapException(JsonMappingException exception) {
LOGGER.error(exception.getMessage(), exception);
List<Reference> references = exception.getPath();
if (references != null) {
String message = new String("Wrong elements: ");
for (Reference reference : references) {
message += reference.getFieldName() + ", ";
}
message = message.substring(0, message.length() - 2);
message += ".";
return new Status("error.rest.badrequest", null, BAD_REQUEST, new Reason(
new StaticLocalizedMessage(message), null, null));
}
return new Status("error.rest.badrequest", null, BAD_REQUEST);
}
示例14: handle
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
/**
* Handle messages of {@link JsonMappingException}
*
* @param exception
* {@link JsonMappingException}
* @param apiResult
* error result
* @return {@link ApiResult} with error messages
*/
@Override
public ApiResult<Object> handle(JsonMappingException exception, ApiResult<Object> apiResult) {
apiResult.setMessage(getErrorMessage(exception));
List<Reference> references = exception.getPath();
List<ApiResultError> apiResultErrors = new ArrayList<ApiResultError>();
if (references != null) {
ApiResultError error = new ApiResultError();
error.setCause("Exception");
String message = new String("wrong elements: ");
for (Reference reference : references) {
message += reference.getFieldName() + ", ";
}
message = message.substring(0, message.length() - 2);
message += ".";
error.setMessage(message);
apiResultErrors.add(error);
}
apiResult.setErrors(apiResultErrors);
return apiResult;
}
示例15: testConvertToCNTMessage
import org.codehaus.jackson.map.JsonMappingException; //导入依赖的package包/类
/**
* Test convert to cnt message.
*
* @throws MessageParsingException
* in case parsing went wrong
* @throws JsonParseException
* the json parse exception
* @throws JsonMappingException
* the json mapping exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testConvertToCNTMessage() throws MessageParsingException, JsonParseException,
JsonMappingException, IOException {
TransferMessage tm = new TransferMessage();
String testContent = "Test Content";
tm.setContentType(TMContentType.JSON);
tm.setContent(testContent);
TestMessage testMessage = new TestMessage();
EasyMock.expect(mockObjectMapper.readValue(testContent, TestMessage.class))
.andReturn(testMessage);
mockObjectMapper.registerSubtypes(new Class[0]);
EasyMock.replay(mockObjectMapper);
converter.setMapper(mockObjectMapper);
TestMessage res = converter.convertToCommunoteMessage(tm,
TestMessage.class);
Assert.assertEquals(res, testMessage);
}