本文整理汇总了Java中org.codehaus.jackson.map.ObjectMapper.convertValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.convertValue方法的具体用法?Java ObjectMapper.convertValue怎么用?Java ObjectMapper.convertValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.map.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.convertValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerBroadcastReceiver
import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
private void registerBroadcastReceiver() {
gameBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String destModelId = extras.getString("modelId");
if (modelId != null && modelId.equals(destModelId)) {
//gotta handle this message
Document messageDocument = dataService.loadDocument(extras.getString("id"));
ObjectMapper mapper = JSONUtils.createObjectMapper();
final GameMessage message = mapper.convertValue(messageDocument.getProperties(), GameMessage.class);
intent.putExtra(Intent.EXTRA_DATA_REMOVED, true);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
controllerFragment.processMessage(message);
}
});
}
}
};
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
gameBroadcastReceiver,
new IntentFilter(GameBoardApplication.INTENT_ACTION_GAME_MSG));
}
示例2: create
import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
@Override
@Transactional
public JpaMedia create(final Map<String, String> mediaDataMap, final Map<String, Object> mediaFileDataMap) {
final ObjectMapper objectMapper = new ObjectMapper();
final JpaMedia media = objectMapper.convertValue(mediaDataMap, JpaMedia.class);
// filename can be the full path or just the name that is why we need to convert it to Paths
// to extract the base name e.g. c:/jdk.zip -> jdk.zip or jdk.zip -> jdk.zip
final String filename = FilenameUtils.getName((String) mediaFileDataMap.get("filename"));
try {
mediaDao.findByNameAndType(media.getName(), media.getType());
final String msg = MessageFormat.format("Media already exists with name {0} and type {1}", media.getName(), media.getType());
LOGGER.error(msg);
throw new MediaServiceException(msg);
} catch (NoResultException e) {
LOGGER.debug("No Media name conflict, ignoring not found exception for creating media ", e);
}
final String uploadedFilePath = repositoryService.upload(filename, (BufferedInputStream) mediaFileDataMap.get("content"));
final List<String> binariesByBasename = repositoryService.getBinariesByBasename(FilenameUtils.removeExtension(filename));
final String dest = getPathForExistingBinary(uploadedFilePath, binariesByBasename);
final Set<String> zipRootDirSet = fileUtility.getZipRootDirs(dest);
if (!zipRootDirSet.isEmpty()) {
media.setRootDir(Paths.get(StringUtils.join(zipRootDirSet, ",")));
media.setLocalPath(Paths.get(dest));
return mediaDao.create(media);
}
repositoryService.delete(dest);
throw new MediaServiceException(MessageFormat.
format("{0} does not have any root directories! It may not be a valid media file.", filename));
}
示例3: createResponse
import org.codehaus.jackson.map.ObjectMapper; //导入方法依赖的package包/类
/**
* Creates response object from response map.
* @param responseMap response map
* @return response object
*/
private ActionResponseData createResponse(Map<String, Object> responseMap) {
Class<? extends ActionResponseData> responseClass = actionService.lookupResponseClass((String) responseMap.get("id"));
ObjectMapper mapper = new ObjectMapper();
return mapper.convertValue(responseMap, responseClass);
}