I think this will work: 
String val;
if (node.isValueNode()) {
		node val = asText());
}
 else {
//ObjectNode
             val = node.toString();
}