我试图java.util.Date使用fastxml jackson在mongo集合中持久化一个具有字段的java对象.问题是objectMapper的默认性质是将Date存储为NumberLong类型.
例如,类型createdTime字段java.util.Date存储如下:
"createdTime" : NumberLong("1427728445176")
我想将它存储在mongo Shell中可用的ISODate格式中.
现在,我知道有办法格式化对象映射器以将日期存储在字符串dateformat中.但我只是在寻找ISODate()格式.
例如
"createdTime" : ISODate("2015-01-20T16:39:42.132Z")
有没有办法做到这一点 ?请告知大师.在此先感谢您的帮助.
我正在使用JSCH -SSH库在"shell"通道中执行命令,但无法找到办法做两件事: -
1)如何查找命令是否在远程unix盒上完全执行?
2)如何捕获String中的命令输出,而不是在System.out控制台上打印它?
下面是我的代码片段,可以在system.out上显示shell命令输出
注意:我不想使用"exec"通道,因为它为每个命令启动一个新进程,并且不记得导出的"会话"变量.我必须使用"shell"频道.
以下是我的代码段.感谢任何帮助.谢谢你的时间.
try{
String commandToRun = "ls /tmp/*.log \n";
if(channel.isClosed())
channel=session.openChannel("shell");
byte[] bytes = commandToRun.getBytes();
ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
channel.setInputStream(bais);
InputStream ins=channel.getInputStream();
channel.connect();
channel.setOutputStream(System.out);//This prints on console. Need 2 capture in String somehow?
//in-efficient way to allow command to execute completely on remote Unix machine
//DO NOT know a better way, to know when command is executed completely
Thread.sleep(5000L);
}
catch(Exception e){
System.out.println("Exception in executeCommand() --->"+ e.getMessage());
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)