null

Empty json object instead of null, when no data -> how to deserialize with gson

霸气de小男生 提交于 2019-12-11 02:59:46
问题 I am trying to parse json data with Google's gson library. But the json data doesn't behave well. It does look like this when everything is alright: { "parent": { "child_one": "some String", "child_two": "4711", ... } } child_one should be parsed as String , child_two as int . But sometimes one of the children has no values what results in an empty object instead of null , like this: { "parent": { "child_one": "some String", "child_two": {}, ... } } I have no access to alter the json feed, so

Finding record where polymorphic association or nil

青春壹個敷衍的年華 提交于 2019-12-11 02:52:51
问题 I have a rails app running ruby 2.1.2 and rails 4.1.1 and in it I have a polymorphic association like so: class Picture < ActiveRecord::Base belongs_to :imageable, polymorphic: true end class Employee < ActiveRecord::Base has_many :pictures, as: :imageable end class Product < ActiveRecord::Base has_many :pictures, as: :imageable end I want to be able to find all Pictures that either belong to a given Employee or have no associated "imageable" record. # These both work fine Picture.where

MsSQL xml parse to decimal

此生再无相见时 提交于 2019-12-11 02:52:48
问题 I'm processing xml with this stored procedure select col.query('./AgreementId').value('.','uniqueidentifier') as [AgreementId], x.query('./GrossValue').value('.','decimal(19, 4)') as [GrossValue] into #AdvanceInvoices from @XML.nodes('/DataFromERP/CustomObjects/Agreements/Agreement') as ref(col) cross apply ref.col.nodes('AdvanceInvoices/AdvanceInvoice') as T(x) The problem is GrossValue, which can be empty <GrossValue></GrossValue> and probably when it is, I get an error Error converting

Issue with JSON null handling in Newtonsoft

微笑、不失礼 提交于 2019-12-11 02:44:15
问题 I have an issue with null handling when dealing Newtonsoft.json . I want to check the result is null or not. Based on that I want to handle some condition. My code is as below: try { var response = GetApiData.Post(_getApiBaseUrl, data.ToString()); var jsonString = response.ResultString; var jsonContent = JObject.Parse(jsonString); if (jsonContent["User"] != null) // <-- null handling { var user = JToken.Parse(jsonContent["User"].ToString()); membershipUser = GetMembershipUser(user); } } The

SQLite default value if null

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 02:39:10
问题 Let's say I have a table called "table" So Create Table "Table" (a int not null, b int default value 1) If I do a " INSERT INTO "Table" (a) values (1) ". I will get back 1 for column a and 1 for column b as the default value for column b is 1. BUT if I do " INSERT INTO "Table" (a, b) values (1, null) ". I will bet back 1 for column a and an empty value for column b. Is there a way to set a column's default value if a null was given? 回答1: No, if you are doing: INSERT INTO my_table (a, b)

How to avoid nest 「null check」by “?.let”?

醉酒当歌 提交于 2019-12-11 02:15:05
问题 let in kotlin help me avoid some if(null?) doSomething. But I have a problem. A is the field of the object, And B is the field of Object A. they can be nullbale. They in code like this. class Obj { var a : A? } class A { var b : B? } I knew I can do it by double let: A?.let { it.B.let { // a must nonnull } } A?.B?.let { // how to use A ,without null check again? } 回答1: There are extension functions out there to achieve what you're looking for, you can find them in this thread https://discuss

String says its not null but then later throw NullPointerException

核能气质少年 提交于 2019-12-11 02:13:34
问题 OMG. I have a little project to do and the Strings are killing me! Now, I have a String which is null (is taken the value from invoking getParameter() from a servlet). The problem is that, I'm trying to see if it's null, and, even if it's null, in the program is telling me that is not null , but later in program, when I'm using the variable, I receive a exception saying the variable is null . System.out.println("In " + ID); // in console: In null if ((ID == null) || (ID == "null") || ID

Return 0 in GROUP BY when COUNT(*) is NULL

旧巷老猫 提交于 2019-12-11 02:09:46
问题 Here is my original query: SELECT CAST(IndexedDate as varchar), COUNT(*) AS Logins FROM Table WHERE EventType = 'Login' AND IndexedDate > DATEADD(mm, -1, GETDATE()) GROUP BY IndexedDate ORDER BY IndexedDate DESC This would leave gaps, for example: 2016-09-13 41 2016-09-12 31 2016-09-09 15 2016-09-08 36 Based on this question, I tried the following and still received the gaps but on top of that the results were wrong (the numbers were MUCH higher): SELECT CAST(IndexedDate as varchar), SUM(Case

C/C++ nullptr dereference [duplicate]

别等时光非礼了梦想. 提交于 2019-12-11 02:04:07
问题 This question already has answers here : Is there a platform or situation where dereferencing (but not using) a null pointer to make a null reference will behave badly? (6 answers) Closed 3 years ago . Since de-referencing nullptr ( NULL ) is an undefined behavior both in C and C++ , I am wondering if expression &(*ptr) is a valid one if ptr is nullptr ( NULL ). If it is also an undefined behavior, how does OFFSETOF macro in the linked answer work? I always thought that ptr->field is a

Whats the Difference between Object.Equals(obj, null) and obj == null

醉酒当歌 提交于 2019-12-11 01:32:07
问题 Almost every time I want to check object's equality to null I use the normal equality check operation if (obj == null) Recently I noticed that I'm using the Object.Equals() more often if (Object.Equals(obj, null)) and while reading about null checking I fount this Is ReferenceEquals(null, obj) the same thing as null == obj? if (ReferenceEquals(null, obj)) Whats the difference? and where/when to use each one? plus I found that the last two checks look like the same according to their summary