File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
src/Nest/CommonOptions/Scripting Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ internal class ScriptFormatter : IJsonFormatter<IScript>
2323
2424 public IScript Deserialize ( ref JsonReader reader , IJsonFormatterResolver formatterResolver )
2525 {
26+ if ( reader . GetCurrentJsonToken ( ) == JsonToken . String )
27+ {
28+ var scriptValue = reader . ReadString ( ) ;
29+ return new InlineScript ( scriptValue ) ;
30+ }
31+
2632 if ( reader . GetCurrentJsonToken ( ) != JsonToken . BeginObject )
2733 {
2834 reader . ReadNextBlock ( ) ;
Original file line number Diff line number Diff line change 1+ // Licensed to Elasticsearch B.V under one or more agreements.
2+ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+ // See the LICENSE file in the project root for more information
4+
5+ using System . Text ;
6+ using Nest ;
7+ using System . Runtime . Serialization ;
8+ using System . IO ;
9+ using FluentAssertions ;
10+ using Elastic . Elasticsearch . Xunit . XunitPlumbing ;
11+
12+ namespace Tests . Reproduce
13+ {
14+ public class GitHubIssue5684
15+ {
16+ private static readonly byte [ ] ResponseBytes = Encoding . UTF8 . GetBytes ( @"{
17+ ""script"": ""doc['sales_price'].value * 2""
18+ }" ) ;
19+
20+ [ U ]
21+ public void DeserialiseSimpleScript ( )
22+ {
23+ var client = new ElasticClient ( ) ;
24+ var result = client . RequestResponseSerializer . Deserialize < Sample > ( new MemoryStream ( ResponseBytes ) ) ;
25+ result . Should ( ) . NotBeNull ( ) ;
26+ result . Script . Should ( ) . BeOfType < InlineScript > ( ) . Subject . Source . Should ( ) . Be ( "doc['sales_price'].value * 2" ) ;
27+ }
28+
29+ private class Sample
30+ {
31+ [ DataMember ( Name = "script" ) ]
32+ public IScript Script { get ; set ; }
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments