【java-JAXB解组对嵌套对象始终为null值】教程文章相关的互联网学习教程文章

java-在struts中,如何获取布尔值的null?【代码】

例如class TestAction {@Getter @SetterBoolean enabled;// null for both }的HTML<input type='radio' name="enabled" value='true'> enabled <input type='radio' name="enabled" value='false'> disabled <input type='radio' name="enabled" value='null'> both <!-- value=null will convert to false -->如何为布尔值传递null? 更新 答案是不可能的.我在下面使用另一种方式.解决方法:我的解决方法.@Data // Generate all se...

java-匿名对象上的Gson“ toJson”返回null

我想使用Gson为String创建一个匿名对象. 我的对象不是null,但是方法“ toJson”返回null. 我怎样才能解决这个问题?解决方法:从users guide:Gson can also deserialize static nested classes. However, Gson can not automatically deserialize the pure inner classes since their no-args constructor also need a reference to the containing Object which is not available at the time of deserialization.Gson不执行序列化...

java-异常处理反模式:为什么记录并返回null是反模式【代码】

关于异常处理反模式的文章提到(参考:https://today.java.net/article/2006/04/04/exception-handling-antipatterns)“ Log and Return Null”是反模式.给出的原因是“不是返回null,而是引发异常,然后让调用方对其进行处理.您仅应在正常(非异常)用例中返回null” 根据这篇文章,以下代码是不良的编程习惯和反模式catch (NoSuchMethodException e) {LOG.error("Blah", e);return null; }catch (NoSuchMethodException e) {e.printSta...

java-@Resource为String类的bean返回null【代码】

我是Spring的新手,但遇到以下问题:我有以下bean: < bean id =“ lastName” class =“ java.lang.String”> < constructor-arg value =“ Johnson” />< / bean> 然后,在我的类RegisterPerson中,我有以下内容@Configurable public class RegisterPerson@Resource(name="lastName")private String lastName;然后在我的方法中displayName(){ System.out.println(姓) } lastName为null. 我查找了一些示例,但找不到与我的问...

通用Java记录器输出类和成员名的null.null【代码】

我将通用java.util.logging.Logger与以下初始化行结合使用:private static final Logger _log = Logger.getLogger(Login.class.getName());然后我像这样使用它(只是一个例子):_log.log(Level.FINE, "Session id: {0}.", session.getId());有时在日志中可以看到以下内容: 2014年11月24日17:26:13.692 FINE [http-nio-80-exec-1] null.null会话ID:18BD6989930169F77565EA2D001A5759. 但是大多数时候,它向我显示了正确的调用类和...

java-从firebase检索返回NULL的数据【代码】

当我调用listPost()时,它将返回NULL.我想它不会等待侦听器从Firebase获取帖子.在返回arrayPost之前,如何等待从firebase提取帖子?public Post[] listPost() {ArrayList<Post> list = new ArrayList<Post>();// Fetch post from firebasepostRef.addValueEventListener(new ValueEventListener() {@Overridepublic void onDataChange(DataSnapshot snapshot) {for(DataSnapshot child : snapshot.getChildren()) {String id = child...

Java枚举属性根据访问顺序返回null【代码】

我正在用Java探索枚举,看看它们如何被滥用,并且遇到了无法解释的行为.考虑以下类别:public class PROGRAM {public enum ENUM {;public enum ANIMALS {;public enum CATS {FELIX(DOGS.AKAME),GARFIELD(DOGS.WEED),BUBSY(DOGS.GIN);CATS(DOGS dog) {this.RIVAL = dog;}public DOGS RIVAL;} public enum DOGS {GIN(CATS.FELIX), WEED(CATS.BUBSY), AKAME(CATS.GARFIELD);DOGS(CATS cat) {this.RIVAL = cat;}public CATS RI...

java-实现ApplicationContextAware-ApplicationContext为NULL【代码】

我正在编程一个Tomcat应用程序,该应用程序充当某些内部服务的代理. 我已经将Spring项目从混合的基于XML和基于注释的配置切换为Java和基于注释的配置. 在切换配置样式之前,该应用程序运行良好.现在我有两个问题. >在我的两个过滤器中执行初始化方法时,ApplicationContext为null.当我调试我的应用程序时,我可以看到方法setApplicationContext已执行.> EntityManagerFactory没有注入到认证过滤器中(emf为空) 引导Spring的代码: impor...

java-Spring dataSource返回null【代码】

我正在尝试将MySQL数据库与Spring连接.我也想将DataSource setter方法与@Autowired一起使用.每次运行代码时,DataSource始终返回null. 错误:HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException有人可以告诉我我的代码有什么问题吗?请在下面找到我的代码. CustomerController.javapackage com.springapp.controller;import com.springapp.beans.Customer; import com.springapp.se...

java-静态方法中的Spring context null【代码】

我正在尝试在Spring MVC-Hybris Application中使用spring应用程序上下文,但是它始终为null.public class FlexSelector{ protected static final ApplicationContext ctx = Registry.getApplicationContext();protected static final PropertiesReader getPropertiesReader(){ return (PropertiesReader) ctx.getBean("serviceExtensionPropertiesReader"); }protected static final SearchRestrictionService getSearchRestriction...

java-选择获取一个返回null的结果【代码】

当我使用此语句时,它不会返回结果.Result<Record> result = (Result<Record>) jooq.select().from("Employees").where(DSL.cast("FirstName", MySQLDataType.BINARY).eq(DSL.cast(firstName, MySQLDataType.BINARY))).fetchOne();我只选择一个结果. 结构体:-- -- Table structure for table `Employees` --CREATE TABLE IF NOT EXISTS `Employees` ( `id` int(11) NOT NULL,`FirstName` varchar(100) NOT NULL,`LastName` varchar...

java-Android Firebase-为什么忽略Map字段中的Null值【代码】

我在Android上使用Firebase在使用地图字段保存POJO时发现,如果该地图在该地图的value属性中包含null,则整个字段都将被忽略. 解决方法很简单(非null值将成功保存地图),但是我想了解为什么会这样? 模型public class Game {private String owner;private Map<String, String> characters;public Game() {// empty constructor for Firebase}public String getOwner() {return owner;}public void setOwner(String owner) {this.owner...

java-集成测试期间@Context为null【代码】

我在其余应用程序上使用spring boot 1.3.0.我正在尝试使用RestAssured创建集成测试.@Context出现问题.对于我来说,它不会注入到控制器中以获取URI. 这是测试类:@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebIntegrationTest("server.port=8080") @ActiveProfiles(value = {"testing"}) public class InvoiceRestServiceIT {private static String INVOICE_DATA = "...

java-Spring MVC中请求标头为null【代码】

我的控制器中有两种映射方法.一个正在重定向到另一个. 重定向之前,我设置了一个标题作为响应.但是我得到的请求标头为空. 这些是我在控制器中的方法.两者都在同一个控制器中.@RequestMapping(value="/testStart", method=RequestMethod.POST)public String testStart(HttpServletRequest request, HttpServletResponse response){String token = "126712810-1289291":response.addHeader("authToken", token);return "redirec...

java-Jackson Mapper序列化空对象而不是null【代码】

说我上课了public class Foo {private Bar bar; }和酒吧public class Bar {private String fizz;private String bang; }编辑:为澄清起见,我不拥有Foo和Bar,并且不能更改这些类. 如果我要序列化Foo类型的空对象,则该对象的成员(其类型为Bar)将返回null.String json = objectMapper.writeValueAsString(new Foo()); // "{"bar" : null}"有什么方法可以使对象映射器序列化一个空的Bar对象,而不必实例化Bar的新实例,然后将其添加到Foo...