Browsing 7239 questions and answers with Jon Skeet

Empty array in string breaking deserialization

I have a string of JSON that I'm trying to convert into a list. There is an empty array value which is breaking the deserialization (have tried removing it manually or changing to...
Jon Skeet
people
quotationmark

The value is an array, but your field is a string. I suggest you make it an array (or list) of the appropriate type - we can't tell what that type would be from your JSON, but perhaps you want a string array? I'd also suggest using... more 5/25/2017 4:29:20 PM

people

Decryption using Aes fails

I am using this function to encrypt data in my UWP project: public string Encrypt(string text, string key) { byte[] buffer = Encoding.UTF8.GetBytes(text); ...
Jon Skeet
people
quotationmark

The problem is what you're doing with the end of the decryption: return Convert.ToBase64String(buffer); You actually want to convert the decrypted binary data back into a string in a way that mirrors the original way you converted it... more 5/25/2017 12:42:22 PM

people

Operator '?' cannot be applied to operand of type 'T' (2)

I came across a weird behavior of C# compiler (VS 2015). In the code bellow, compiler is happy with Value2, but complains about Value1: Operator '?' cannot be applied to operand...
Jon Skeet
people
quotationmark

I believe the problem is that the compiler can't know the type of the expression _valueProvider?.Value. Let's simplify this a bit: public interface IValueProvider<T> { T Value { get; } } public class Test { public static... more 5/25/2017 7:38:58 AM

people

.net core / standard string.ToLower() has no culture parameter

In .net fx i can do myString.ToLower(frenchCulture); But when looking at .net core or .net standard there is no more a culture parameter that can be passed. There is only...
Jon Skeet
people
quotationmark

It looks like the capability is there, just in a more roundabout way. Instead of: string output = input.ToLower(culture); use string output = culture.TextInfo.ToLower(input); Also note that the overload has been added in... more 5/24/2017 10:51:16 AM

people

Parsing Json to zoned date time

Im reciving following json time format "TimeEnd": "2017-05-24 09:52:51+02:00" my dto is as follows: @JsonProperty("TimeEnd") @JsonDeserialize(using =...
Jon Skeet
people
quotationmark

You shouldn't be trying to parse it as a ZonedDateTime, as it really doesn't have a time zone - it has a UTC offset. OffsetDateTime is more appropriate here. It's worth differentiating between the two types - you can create a ZonedDateTime... more 5/24/2017 10:24:38 AM

people

In java.time.Period class, what are the purposes of withDays(), withMonths(), withYears()

I noticed that the java.time.Period class contains a few instance methods that behave the same as the available static factory methods. .withDays() behaves the same as...
Jon Skeet
people
quotationmark

You made an unfortunate choice to test with, basically - "weeks" isn't an independent unit; it's just a shorthand for 7 days. From the docs for ofWeeks: The resulting period will be day-based, with the amount of days equal to the... more 5/24/2017 10:06:48 AM

people

Java main method not found error on Windows 10 even with correct main signature

I have a couple of Java files A.java and B.java that use a common jar file C.jar. B.java contains reference variables to the object of type A. B.java contains the main method I...
Jon Skeet
people
quotationmark

Am I making some mistake in my commands? Yes - you're not including anything apart from C.jar when trying to run. Use java -cp C.jar;. // Windows java -cp C.jar:. // Unix So that you're including the current directory (which is... more 5/24/2017 7:46:34 AM

people

how to convert optional parameter method to delegate in c#

i have a casting problem. public void Test(int a = 0) { } System.Action d = Test; this code works well in unity 5. but visual studio 2015 can't compile it. CS0123 No...
Jon Skeet
people
quotationmark

I'm surprised it works in Unity - it shouldn't. That sounds like a Mono compiler bug. The C# 5 specification isn't as clear on this as it should be, but from the draft of the upcoming ECMA C# 5 standard, from the clause on method group... more 5/24/2017 6:06:34 AM

people

Java Regex to replace Octal value in string

I have set of octal values say (0177-0377). whenever these value I found in string, have to replace with ?. String a= "sccce¼»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕerferferfer"; for...
Jon Skeet
people
quotationmark

You don't want to do this to the whole file in one go - you need a streaming approach. I'd do something like this: // TODO: Rename to something more appropriate public static void replaceInvalidCharacters(Reader reader, Writer writer) { ... more 5/23/2017 1:33:50 PM

people

How to convert the Date format and store it in a Date field(not in string or println) with the new format in Java

I'm trying to get the date from an object and changing the format and down the line I need to use the date value as a date field itself(not as string). The format is getting...
Jon Skeet
people
quotationmark

A Date object doesn't have any state representing a format. It's just an instant in time. If you've got the right value in date1, then formatting and parsing it is completely pointless. Instead, when you want the Date in a particular... more 5/23/2017 12:25:55 PM

people